Issue:
When we use Java Dynamic proxy, method. invoke () is a necessary step to call the real method we want. but once this method triggers an exception during execution, the final exception printed out is always "Java. lang. reflect. invocationtargetexception ". so,
How can we know that which exact exception caused JVM throw invocationtargetexception?
Solution:
We can use E. getcause () to get this info, such
Issue: When we use Java Dynamic proxy, method. invoke () is a necessary step to call the real method we want. but once this method triggers an exception during execution, the final exception printed out is always "Java. lang. reflect. invocationtargetexception ". so, how can we know that which exact exception caused JVM throw invocationtargetexception? Solution: We can use E. getcause () to get this info, such as public object invoke (Object proxy, method, object [] OBJ) throws throwable {object result = NULL; try {result = method. invoke (Delegation, OBJ);} catch (exception e) {matchexception (E);} return result;} private void matchexception (exception e) {system. out. println (E. getcause (); If (E. getcause () instanceof subexception) {system. out. println ("this is subexception. ");} else if (E. getcause () instanceof baseexception) {system. out. println ("this is baseexception. ") ;}}