3 ms·
No, that will force whoever is calling your method to handle that exception, now without knowing the actual context ("why does getWeatherForecast() throw Malfor
by sfjailbird 13y ago
No, that will force whoever is calling your method to handle that exception, now without knowing the actual context ("why does getWeatherForecast() throw MalformedURLException?" etc.). It also leaks an implementation detail, i.e. the use of URL-whatever.
A RuntimeException, and any subclass of it, is unchecked and so the compiler does not force you to handle it.
- StavrosK 13y agoOh, right, you convert it to RuntimeException (ostensibly in multiple places where you don't want to handle the exception) and catch that one as a general exception. It makes sense now and sounds like a good solution, thank you.
- tomjen3 13y agoIt is a horrible solution, but it does work. IMHO, go was right to get rid of exceptions (stack traces are useful) and just return two values.