Add exception handling to event bus, and a flag to indicate a unhandled exception to the Event base class

This commit is contained in:
Aria 2023-06-26 01:25:28 -07:00
parent 8976d8fb7f
commit 6fdfa52e1a
2 changed files with 10 additions and 0 deletions

View file

@ -3,6 +3,13 @@ package dev.zontreck.ariaslib.events;
public abstract class Event {
private boolean isCancelled=false;
/**
* True is the event ended early due to a unhandled exception.
*
* The event bus will continue processing.
*/
public boolean exceptionThrown = false;
public Event()
{

View file

@ -80,6 +80,9 @@ public class EventBus
eventContainer.function.invoke(eventContainer.containingClass, event);
} catch (IllegalAccessException|IllegalArgumentException|InvocationTargetException | SecurityException e) {
e.printStackTrace();
} catch (Exception e)
{
event.exceptionThrown=true;
}
cancelled=event.isCancelled();