AssertionFailedError: Method throwed runtime exception

I have modified getStockQuotes() in AlphavantageService.java to throw StockQuoteServiceException when the API result is null or it represnts an invalid Json.

Still my code only throws RuntimeException as indicated by the error.

Can anyone point what I am doing wrong??

@TanG are you throwing the error simply as throw new RuntimeException() ?

No, after checking for the below three cases :

  1. You are not able to process the response from a third-party service.
  2. The response from a third-party service contains an error or is otherwise invalid.
  3. If the response contains no data.

then throw new StockQuoteServiceException(“message”);

@TanG you’ve to catch those exceptions and need to throw your specified exceptions. If you’re doing that, please check that you’re doing it correctly or not. because It should’ve worked.

@TanG

No, you dont need to compare the result if its null or not, coz the function will automatically throw the nullpointerexcecption if it found one and result in RuntimeException, so all you have to do is catch all the expected exceptions like RuntimeException, JsonMappingException etc and throw your specified one inside of them.

Thanks for your help
the issue is resolved now :slight_smile:

1 Like

Closing this topic as your issue is resolved by the community. If it is still not resolved, please feel free to create a new topic and post this question as a reference link in the description of the new topic.