从 Method.invoke 方法调用该方法时,我似乎无法在代码中捕获异常。如何从方法本身内部捕获它?
void function() {
try {
// code that throws exception
}
catch( Exception e ) {
// it never gets here!! It goes straight to the try catch near the invoke
}
}
try {
return method.invoke(callTarget, args);
}
catch( InvocationTargetException e ) {
// exception thrown in code that throws exception get here!
}
谢谢!