mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-17 19:05:08 +00:00
Improve exceptions thrown on module lifecycle events (#105)
Make exceptions thrown by events in modules look nicer by removing the awkward InvocationTargetException wrapper. InvocationTargetException is a wrapper used when a method invoked by reflection itself throws an exception. This lets the log be a bit nicer as we don't have a useless part of the stacktrace just telling us an exception was thrown Also rethrow runtime exceptions as is so we don't add the exception handler to the stack trace unnecessarily
This commit is contained in:
1 parent
385ef0153e
commit
dc0fea44df
2 files changed
+13
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package slimeknights.mantle.pulsar.flightpath;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@@ -88,7 +89,15 @@ public class Flightpath {
|
||||
m.setAccessible(true);
|
||||
m.invoke(ent.getKey(), evt);
|
||||
m.setAccessible(access);
|
||||
} catch(InvocationTargetException ex) {
|
||||
// thrown when a method throws an exception, so use that exception instead of the wrapper for a better stacktrace
|
||||
if(ex.getTargetException() instanceof Exception) {
|
||||
exceptionHandler.handle((Exception)ex.getTargetException());
|
||||
} else {
|
||||
exceptionHandler.handle(ex);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
// all other exceptions, this means something when wrong with the reflection
|
||||
exceptionHandler.handle(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,10 @@ public final class BusExceptionHandler implements IExceptionHandler {
|
||||
@Override
|
||||
public void handle(Exception ex) {
|
||||
this.logger.error("Exception caught from a pulse on flightpath for mod ID " + id + ": ", ex);
|
||||
// if its a runtime exception, we can just throw it as is
|
||||
if(ex instanceof RuntimeException) {
|
||||
throw (RuntimeException)ex;
|
||||
}
|
||||
throw new Error(ex);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user