Interface EventErrorHandler
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
When an event handler registered via
CopilotSession.on(java.util.function.Consumer) or
CopilotSession.on(Class, java.util.function.Consumer) throws an
exception, the EventErrorHandler is invoked with the event that was
being dispatched and the exception that was thrown.
Errors are always logged at Level.WARNING
regardless of whether an error handler is set. The error handler provides
additional custom handling such as metrics, alerts, or integration with
external error-reporting systems:
session.setEventErrorHandler((event, exception) -> {
metrics.increment("handler.errors");
logger.error("Handler failed on {}: {}", event.getType(), exception.getMessage());
});
Whether dispatch continues or stops after an error is controlled by the
EventErrorPolicy set via
CopilotSession.setEventErrorPolicy(EventErrorPolicy). The error
handler is always invoked regardless of the policy.
If the error handler itself throws an exception, that exception is caught and
logged at Level.SEVERE, and dispatch is stopped
regardless of the configured policy.
- Since:
- 1.0.8
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidhandleError(AbstractSessionEvent event, Exception exception) Called when an event handler throws an exception during event dispatch.
-
Method Details
-
handleError
Called when an event handler throws an exception during event dispatch.- Parameters:
event- the event that was being dispatched when the error occurredexception- the exception thrown by the event handler
-