Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to rethrow the original Exception caught by InvocationTargetException

419219Mar 3 2010 — edited Mar 31 2010
I 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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 28 2010
Added on Mar 3 2010
9 comments
1,112 views