HandlerExecutionException stacktrace necessary?

As handler execution exceptions are wrappers for actual exceptions and optional error codes, it looks like HandlerExecutionException stacktrace does not bring real value.

I wonder if it would be sensible to introduce constructors with a writableStackTrace flag (could be true by default for backward compatibility) to avoid performance penalties while constructing these wrapper exceptions?

Hi Damir,

Thank you for your question. Would you please share some more information about this scenario? Is it for command or query exceptions? And what are the performance penalties you are referring to?

Thanks again and I look forward to hearing more about your specific case.

Kind regards,

Let me say first, there is no real problem that I’m experiencing. I just think there is an opportunity for some improvement when dealing with handler execution exceptions (either command or query).

As handler execution exceptions are essentially just wrappers intended to communicate error codes over the (grpc) wire, I believe there is no real benefit in creating a stack trace during handler execution exception construction.

Usually, stacktrace is created implicitly for all Java exceptions, unless disabled explicitly via a constructor parameter. In the source code of Java RuntimeException, for example, that boolean parameter is called writableStackTrace.

Unfortunately, the creation of stacktrace is a performance-intensive operation and would be best if it can be avoided. Stacktrace removal is not something that should be done commonly for exceptions in Java. However, in the case of handler execution exceptions, I believe it makes sense to offer writableStackTrace as a constructor parameter as there is no real benefit in creating stacktrace for that particular scenario.

If relevant, a good explanation (and measurement) of various aspects of exception handling is available here: The Exceptional Performance of Lil' Exception . The article is rather old, and performance is probably improved over the last years, but I believe that the penalty of creating a stacktrace is still significant.

I hope it is clearer now what I’m rambling about :slight_smile:


1 Like

Thank you so much for the clarification and the great explanation Damir. Would you like to open up an issue with your recommendations? We think it’s a great idea to improve and adjust the HandlerExecutionException as well. Thank you again for the suggestion. :slight_smile:


I’m glad you like the idea :slight_smile:

Here is an issue link: Allow creation of HandlerExecutionExceptions without stacktrace · Issue #1901 · AxonFramework/AxonFramework · GitHub



Fantastic! Thank you so much Damir. :slight_smile:

So proud :grinning: :tada: