Generic logging of runtime exceptions which occur in aggregate

Hi all,

We have this exception log in production:
“WARN o.a.c.gateway.DefaultCommandGateway - Command ‘’ resulted in org.axonframework.commandhandling.CommandExecutionException(Error handling event of type [class ] in aggregate)”

This does not provide us enough details to solve this error.

Using the approach below is no solution either.

CompletableFuture result = commandGateway.send();

result.whenComplete((response, e) -> //Here the original exception cause is not available);

So what I would like to implement is an generic error handler which catches all runtime exceptions which happen during the command and/or event handling in an aggregate. This generic handler should have access to the original cause exception so that the cause can be logged to our log file.

How can I implement this in Axon?

We use Axon version 4.2 in combination with Spring Boot 2.1.9.

Best regards,

Hi all,

No response yet, so I try an other way to explain the requirement.

I would like to be able to:

“Implement a generic interceptor which intercepts runtime exceptions when thrown by an event listener (e.g. an aggregate using event sourcing, saga’s or other event handlers)”

I hope this helps by formulation an answer.

Best regards,


Hi Marinus,

Axon offers 2 types of interceptors: Dispatch Interceptors and Handler Interceptors. The former are executed as messages (commands, events or queries) are sent out onto the bus, whereas the latter intercept messages as they arrive from the bus and invoke a handler. The Handler Interceptors have more details on exceptions, as the entire (original) stacktrace is available.
In case of a distributed setup, if you want to pass application-specific details in an exception, you can have your Handler Interceptor wrap the exception in a HandlerExecutionException (or the more specific CommandExecutionException/QueryExecutionException). The “details” object is serialized along with the error message towards the sender.

You can register handler interceptors on their respective buses. Note that you don’t need to do that using the Configuration API. Each Message Bus interface declares a method to register additional handlers.

Hope this helps.

Hi Allard,

Thanks a lot. It helped.

I now registered a handler interceptor on the command bus and event processing configurer. This enables me to implement my logging requirement. For now I use the default LoggingInterceptor for the axon framework.
I could not find a register handler function on the event bus interface. Is that correct?

Best regards,

Hi Marinus,

that’s correct. The handling of events is done inside the EventProcessors, rather than by the Bus itself. That is also where you’ll be able to register your HandlerInterceptors for events.

Kind regards,