Commit 2dc3660a authored by Andy Wilkinson's avatar Andy Wilkinson

Align launcher exception handling with direct invocation of main method

Previously, if an application’s main method threw an exception,
MainMethodRunner would catch the exception and call System.exit(1).
This meant that the JVM would exit, irrespective of whether or not
any non-daemon threads were running. In contrast, when an application’s
main method was invoked directly (in an IDE, for example) the JVM
would not exit if one or more non-daemon threads were running. This
is standard JVM behaviour that we should be consistent with in the
launcher.

This commit updates MainMethodRunner to wrap any exception thrown by an
application’s main method in a RuntimeException and rethrow it. This
alllows the JVM to handle the exception and use its normal rules for
deciding whether or not it should exit.

Closes gh-4984
parent 9f728b3d
...@@ -59,10 +59,7 @@ public class MainMethodRunner implements Runnable { ...@@ -59,10 +59,7 @@ public class MainMethodRunner implements Runnable {
if (handler != null) { if (handler != null) {
handler.uncaughtException(Thread.currentThread(), ex); handler.uncaughtException(Thread.currentThread(), ex);
} }
else { throw new RuntimeException(ex);
ex.printStackTrace();
}
System.exit(1);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment