Unhandled exceptions cause the current thread to exit. If
the current thread is the thread in which main
was
executed, the shutdown sequence will be initiated without waiting for
non-daemon threads to exit. The JVM will exit with a non-zero exit code. See the section called “Exception handling” for unhandled exception
handling when a transaction is active.
Example 3.5, “Unhandled Exception” below shows an unhandled
exception in the main
thread.
Example 3.5. Unhandled Exception
// $Revision: 1.1.2.1 $ package com.kabira.snippets.vmlifecycle; /** * An unhandled exception in main * <p> * <h2> Target Nodes</h2> * <ul> * <li> <b>domainnode</b> = A * </ul> */ public class UnhandledException { /** * Unhandled exception */ public static class MyException extends java.lang.Error { /** * Serialization UID */ public final static long serialVersionUID = 1L; } /** * Main entry point * @param args Not used */ public static void main(String[] args) { // // Throw an unhandled exception - non-zero exit code returned // from main // throw new MyException(); } }
When Example 3.5, “Unhandled Exception” is run the following output is generated:
Example 3.6. Unhandled Exception Output
[A] Java main class com.kabira.snippets.vmlifecycle.UnhandledException.main exited with an exception. [A] Java exception occurred: com.kabira.snippets.vmlifecycle.UnhandledException$MyException [A] at com.kabira.snippets.vmlifecycle.UnhandledException.main(UnhandledException.java:41) [A] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [A] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [A] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [A] at java.lang.reflect.Method.invoke(Method.java:597) [A] at com.kabira.platform.MainWrapper.invokeMain(MainWrapper.java:47) INFO: Application [com.kabira.snippets.vmlifecycle.UnhandledException2] running on node [A] exited with status [-1] INFO: Run of distributed application [com.kabira.snippets.vmlifecycle.UnhandledException2] complete.