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,36 +185,40 @@ 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(() -> {
|
||||||
instance = this;
|
try {
|
||||||
state = EngineState.EARLY_STARTUP;
|
instance = this;
|
||||||
|
state = EngineState.EARLY_STARTUP;
|
||||||
|
|
||||||
new EngineConfiguration();
|
new EngineConfiguration();
|
||||||
EngineConfiguration.getInstance().loadConfiguration();
|
EngineConfiguration.getInstance().loadConfiguration();
|
||||||
|
|
||||||
LOGGER.info("Initializing engine");
|
LOGGER.info("Initializing engine");
|
||||||
initializeClasses(); // Initialize classes
|
initializeClasses(); // Initialize classes
|
||||||
if (checkEnvironment()) // Check environment
|
if (checkEnvironment()) // Check environment
|
||||||
throw new IllegalStateException("Running in an incompatible environment");
|
throw new IllegalStateException("Running in an incompatible environment");
|
||||||
ensureEnvironment(); // Prepare the environment and ensure safety
|
ensureEnvironment(); // Prepare the environment and ensure safety
|
||||||
populateCrashContent(); // Populate crash content
|
populateCrashContent(); // Populate crash content
|
||||||
cacheEvents(); // Cache event listeners
|
cacheEvents(); // Cache event listeners
|
||||||
startThreads(); // Start threads
|
startThreads(); // Start threads
|
||||||
|
|
||||||
LOGGER.verb("Completing early initialization stage");
|
LOGGER.verb("Completing early initialization stage");
|
||||||
state = EngineState.STARTUP;
|
state = EngineState.STARTUP;
|
||||||
|
|
||||||
// Perform automatic subsystem initialization
|
// Perform automatic subsystem initialization
|
||||||
if (EngineConfiguration.getInstance().isInitialPerformSubsystemInitialization()) {
|
if (EngineConfiguration.getInstance().isInitialPerformSubsystemInitialization()) {
|
||||||
collectSubsystems(); // Collect subsystems
|
collectSubsystems(); // Collect subsystems
|
||||||
|
|
||||||
// Initialize subsystems
|
// Initialize subsystems
|
||||||
try {
|
try {
|
||||||
initializeSubsystems();
|
initializeSubsystems();
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
LOGGER.error("Subsystem dependency resolution failed");
|
LOGGER.error("Subsystem dependency resolution failed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception exception) {
|
||||||
|
throw new RuntimeException(exception);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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();
|
||||||
LOGGER.error("Engine initialization failed");
|
else {
|
||||||
LOGGER.error(Miscellaneous.getStackTraceHeader(exception));
|
LOGGER.error("Engine initialization failed");
|
||||||
for (String line : Miscellaneous.getStackTraceAsString(exception, true).split("\n"))
|
LOGGER.error(Miscellaneous.getStackTraceHeader(exception.getCause()));
|
||||||
LOGGER.error(line);
|
for (String line : Miscellaneous.getStackTraceAsString(exception.getCause(), true).split("\n"))
|
||||||
throw new RuntimeException("Engine initialization failed", exception);
|
LOGGER.error(line);
|
||||||
|
throw new RuntimeException("Engine initialization failed", exception.getCause());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue