Support for Java Exception Handling
When you use method-level protection for a Java application, reflection is used for protected methods. Therefore, protected methods that transfer exceptions back to the calling method are limited by reflection.
NOTE If you require protected methods that transfer exceptions without this limitation, consider using class-level protection instead of method-level protection.
Example
catch (ArithmeticException e)
{
System.out.println("Arithmetic Exception");
}
catch (NegativeAgeException e)
{
System.out.println("Negative Age Exception ");
}
catch(InvocationTargetException e)
{
System.out.println("Java Envelope Exception");
}
In this example, Exception always comes in the third exception (generic exception) even if the protected method has thrown ArithmeticException or NegativeAgeException. This happens because an exception thrown by the original protected method is overwritten by reflection with InvocationTargetException.
However, object e is the same as thrown by the original application; therefore, toString will provide the original application exception string.