BAEL-3504: Article - what causes invocation-target-exception : done
This commit is contained in:
parent
ec9028d5f8
commit
bea5cdafe4
@ -0,0 +1,19 @@
|
|||||||
|
package com.baeldung.reflection.exception.invocationtarget;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
public class InvocationTargetDemo {
|
||||||
|
public static void main(String[] args) throws Throwable {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
InvocationTargetExample targetExample = new InvocationTargetExample();
|
||||||
|
Method method = InvocationTargetExample.class.getMethod("divideByZeroExample");
|
||||||
|
method.invoke(targetExample);
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
|
||||||
|
throw e.getCause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.baeldung.reflection.exception.invocationtarget;
|
||||||
|
|
||||||
|
public class InvocationTargetExample {
|
||||||
|
public int divideByZeroExample() {
|
||||||
|
return 1 / 0;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user