How to get a list of all possible exceptions that may occur in a specific area

I have a class class_Abelonging to another class class_Bthat has methods with calls to other objects working with HTTP and JSON. Now I do not want to handle these exceptions at class_B, but rather at a higher level, and thus pass them through throw eto class_A.

Now I am wondering, when in my class Asurrounding method call class_B, with try / catch, how can I get all the possible Exceptions that can be redirected from this method or subclass methods (like HTTP and JSON).

A preferred method would be to get possible Exceptions directly in Eclipse, but other solutions are also appreciated.

(Please let me know if my problem is unclear.)


Update: What I'm looking for is not a real implementation, but rather a list of potential exceptions, so I can see and decide for which cases it is better to create a specific catch block and which Exceptions can be handled by a common catch block.

+3
source share
1 answer

It is not possible to get an exhaustive list Exceptionthat could be thrown away due to RuntimeExceptionwhich should not be declared.

Also, having potentially 20 or more catch blocks for different exceptions (most likely they all do the same thing) will be insane. Instead, you simply do this:

catch(SpecialException e)
{
    // do things specific to that exception type;
    // if there are no such things, just do the
    // general catch below
}
catch(Exception e)
{
    // do generic stuff
}
+3
source

Source: https://habr.com/ru/post/1720270/


All Articles