views:

58

answers:

1

I've a class class_A dealing with another class class_B which has methods with calls to other objects dealing with HTTP and JSON. Now I don't wanna handle these exceptions within class_B but rather on a higher level and thus forward them via throw e to class_A.

Now I'm wondering when in my class A surrounding the call to a method of class_B with try/catch how I can get all the possible Exceptions that could get forwarded from that method or methods of subclasses (like HTTP & JSON).

Preferred would be way to get the possible Exceptions directly in Eclipse, but other solutions are appreciated as well.

(Please let me know if my problem description is not clear.)


Update: What I'm looking for is not an actual implementation, but rather a list of potential exceptions, so I can see and decided for what cases I should better build a specific catch block and which Exceptions can be handled by a generic catch block.

+2  A: 

It's impossible to get an exhaustive list of Exceptions that might be thrown, due to RuntimeExceptions that do not have to be declared.

Besides, having potentially 20 or more catch blocks for different exceptions (most likely all doing the same thing) would 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
}
Michael Borgwardt
Thanks for your answer. I know and understand how to implement multiple catch blocks. However, what I'm looking is not an implementation, but rather a list of potential exceptions, so I can see and decided for what cases I should better build a specific catch block and which Exceptions can be handled by the more generic ones.
znq
As I wrote: there's no technical way to get such a list. Besides, it would not be very useful without information under what circumstances each Exception can occur. A well-documented API should list thsoe exceptions that a client might want to handle specially in the javadoc comments using @throws
Michael Borgwardt