BAEL-3504: Article - what causes invocation-target-exception : done

This commit is contained in:
Vikas Ramsingh Rajput 2020-01-07 21:08:42 +03:00
parent ec9028d5f8
commit bea5cdafe4
2 changed files with 26 additions and 0 deletions

View File

@ -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();
}
}
}

View File

@ -0,0 +1,7 @@
package com.baeldung.reflection.exception.invocationtarget;
public class InvocationTargetExample {
public int divideByZeroExample() {
return 1 / 0;
}
}