How to rethrow the original Exception caught by InvocationTargetException
419219Mar 3 2010 — edited Mar 31 2010I am trying to call a method from class A via class new B().proxyMethodCall() from client class C.
client class C is supposed to handle a user defined exception: UserNotFoundException thrown by class A.
but since class C is calling the method of class A through the proxy class B (via reflection), the exception captured on class B is the InvocationTargetException.
Inside class B,
The original exception is available on the catch block via getTargetException() but it is of type Throwable which is a checked Exception. I do now want to declare throws Throwable since there are too many methods in class B that calls the proxyMethodCall() besides I don't feel it is correct.
How can I rethrow the original exception (inside the catch block of class B perhaps) and make it catchable inside class C as it was when A was being called directly inside C?
I hope it makes any sense. Please help.