Allow throwing all exceptions during engine init
Due to some Java limitation we are required to throw a RuntimeException with our original exception contained within and afterwards unwrap it so we can throw any exception we like. That is dumb.
This commit is contained in:
parent
a21ef1bc5f
commit
d3a01c2c66
1 changed files with 37 additions and 31 deletions
|
@ -185,8 +185,9 @@ public final class Engine extends SubsystemClass {
|
||||||
* @throws IllegalStateException when running in an incompatible environment
|
* @throws IllegalStateException when running in an incompatible environment
|
||||||
* @since v1-alpha6
|
* @since v1-alpha6
|
||||||
*/
|
*/
|
||||||
private Engine() throws IllegalStateException {
|
private Engine() throws RuntimeException {
|
||||||
long initTime = Miscellaneous.measureExecutionTime(() -> {
|
long initTime = Miscellaneous.measureExecutionTime(() -> {
|
||||||
|
try {
|
||||||
instance = this;
|
instance = this;
|
||||||
state = EngineState.EARLY_STARTUP;
|
state = EngineState.EARLY_STARTUP;
|
||||||
|
|
||||||
|
@ -216,6 +217,9 @@ public final class Engine extends SubsystemClass {
|
||||||
LOGGER.error("Subsystem dependency resolution failed");
|
LOGGER.error("Subsystem dependency resolution failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception exception) {
|
||||||
|
throw new RuntimeException(exception);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
LOGGER.verb("Completing late initialization stage");
|
LOGGER.verb("Completing late initialization stage");
|
||||||
|
@ -235,14 +239,16 @@ public final class Engine extends SubsystemClass {
|
||||||
try {
|
try {
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
new Engine();
|
new Engine();
|
||||||
} catch (IllegalStateException exception) {
|
} catch (RuntimeException exception) {
|
||||||
throw exception;
|
if (exception.getCause() instanceof IllegalStateException)
|
||||||
} catch (Exception exception) {
|
throw (IllegalStateException) exception.getCause();
|
||||||
|
else {
|
||||||
LOGGER.error("Engine initialization failed");
|
LOGGER.error("Engine initialization failed");
|
||||||
LOGGER.error(Miscellaneous.getStackTraceHeader(exception));
|
LOGGER.error(Miscellaneous.getStackTraceHeader(exception.getCause()));
|
||||||
for (String line : Miscellaneous.getStackTraceAsString(exception, true).split("\n"))
|
for (String line : Miscellaneous.getStackTraceAsString(exception.getCause(), true).split("\n"))
|
||||||
LOGGER.error(line);
|
LOGGER.error(line);
|
||||||
throw new RuntimeException("Engine initialization failed", exception);
|
throw new RuntimeException("Engine initialization failed", exception.getCause());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue