Allow ExitCodeGenerator to be used on Exceptions
Update exit code support to allow the ExitCodeGenerator interface to be placed on an Exception. Any uncaught exception implementing the interface and returning a non `0` status will now trigger a System.exit with the code. Fixes gh-4803
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.loader;
|
||||
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
@@ -53,7 +54,14 @@ public class MainMethodRunner implements Runnable {
|
||||
mainMethod.invoke(null, new Object[] { this.args });
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
UncaughtExceptionHandler handler = Thread.currentThread()
|
||||
.getUncaughtExceptionHandler();
|
||||
if (handler != null) {
|
||||
handler.uncaughtException(Thread.currentThread(), ex);
|
||||
}
|
||||
else {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user