dispatchExceptionHandlers

private fun dispatchExceptionHandlers(event: Event, throwable: Throwable)

Dispatches a throwable raised by an event handler to registered @ExceptionHandler methods.

This method is invoked from post whenever an event handler throws. It performs the following steps:

  1. Resolves all exception handlers that are applicable to the runtime type of event, using exceptionResolvedCache to avoid repeated hierarchy walks. Resolution includes handlers registered for superclasses and interfaces of the event type.

  2. Sorts the resolved handlers using a composite ordering:

    • Primary: descending Priority.priority (higher first).

    • Secondary: ascending specificityRank, so that handlers with both event and throwable parameters run before event-only, which in turn run before throwable-only handlers at the same priority.

  3. If no handlers are found:

    • If throwable is an Exception, it is logged as an unhandled failure for the given event type and then swallowed.

    • Otherwise (e.g. Error subclasses), throwable is rethrown to avoid masking fatal conditions.

  4. For each handler entry, checks throwable compatibility when the handler declares a concrete throwable type (via ExceptionHandlerEntryWithThrowable). Compatibility is determined using Class.isInstance, so handlers declared for a supertype (such as Exception) may observe subtypes (such as IOException).

  5. Invokes the underlying handler using the appropriate invoker shape:

    • (event: Event, throwable: Throwable)

    • (event: Event)

    • (throwable: Throwable)

Any exceptions thrown by exception handlers themselves are not caught here and will propagate outward. This is deliberate: if an exception handler chooses to throw, it is treated as a terminal failure rather than feeding back into the bus.

Parameters

event

the event whose handler produced throwable.

throwable

the exception thrown while dispatching event.