user1429953
user1429953

Reputation: 33

InvocationTargetException, from this exception how to extract caused exception with message

When run this statement from other Java program.

mainMethod.invoke(null,(Object) args);

I got this Exception

I'm dying!
I'm not dead yet!
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.fourgid.ot.action.RunThread.run(RunThread.java:59)
***Caused by: java.lang.SecurityException
at Main$1.checkExit(Main.java:21)
at java.lang.Runtime.exit(Runtime.java:88)
at java.lang.System.exit(System.java:904)
at Main.main(Main.java:30)***
... 5 more

i just to show only caused exception that is SecurityException with messages and line numbers(above highlighted text) given by JVM.

I am developing an application for compile and execute the program on web.

Thank you!!

Upvotes: 1

Views: 993

Answers (1)

kahowell
kahowell

Reputation: 30146

My suggestion: catch the InvocationTargetException and then try exception.getCause(). You might then be able to get more details from the underlying SecurityException.

Upvotes: 2

Related Questions