How can I use @ExceptionHandler annotation in saga

I tried use it in saga, but it didn’t trigger the ExceptionHandler even though the exception and stack trace was shown on the log, I wonder why. Here’s how the code looks like.

class TestSaga {

  @StartSaga
  @SagaEventHandler(associationProperty = "test")
  fun on(event: EventA) {
    Mono.error(IllegalArgumentException("Test handling from A"))
      .block()!!
  }
  
  @SagaEventHandler(associationProperty = "test")
  fun on(event: EventB) {
    Mono.error(IllegalArgumentException("Test handling from B"))
      .block()!!
  }

  @SagaEventHandler(associationProperty = "test")
  fun on(event: EventC) {
    Mono.error(IllegalArgumentException("Test handling from C"))
      .block()!!
  }
  

  @ExceptionHandler
  fun on(error: IllegalArgumentException) {
    // doesn't trigger this handler
    println("Exception handler tested")
  }
}

I use axonframework version 4.4.8 and also use TrackingEventProcessor

That’s curious what you’re experiencing, @xXExpertAxonUserXx!
I’ve got a couple of things you can try out to see where the predicament lies:

  • Have you tried just throwing the exception directly from the @SageEventHandler block instead of wrapping it in a Mono?
  • Have you tried an @ExceptionHandler annotated method that doesn’t take any parameter?
  • Have you tried an @ExceptionHandler(resultType = IllegalArgumentException.class) annotated method?
  • Have you tried using the latest version of Axon Framework? It’s currently on version 4.5.10.