Pass errors caused during system event dispatch to caller

When an error is caused during the dispatch of a system event, a warning
has been logged instead instead of rethrowing the error. This has been
fixed.

This enables failing a JUnit test when an exception event handler is
invoked.
This commit is contained in:
Kai S. K. Engelbart 2021-07-07 22:06:07 +02:00
parent b758f4cef1
commit 6eebd3c121
Signed by: kske
GPG Key ID: 8BEB13EC5DF7EF13

View File

@ -94,14 +94,14 @@ public final class EventBus {
try {
handlers.next().execute(event);
} catch (InvocationTargetException e) {
if (event instanceof DeadEvent || event instanceof ExceptionEvent)
// Warn about system event not being handled
logger.log(Level.WARNING, event + " not handled due to exception", e);
else if (e.getCause() instanceof Error)
if (e.getCause() instanceof Error)
// Transparently pass error to the caller
throw (Error) e.getCause();
else if (event instanceof DeadEvent || event instanceof ExceptionEvent)
// Warn about system event not being handled
logger.log(Level.WARNING, event + " not handled due to exception", e);
else
// Dispatch exception event