Global Exception Handler


I am trying to figure out a way to have a global exception handler. The idea behind this is to have one spot to catch all exceptions so that we can log them and also send them up to rollbar. In spring there is the @ControllerAdvice that we can use to make sure any web request errors get tracked. However, this does not cover errors thrown in camunda tasks (for example, in a java delegate).

One solution I have is using the camunda-bpm-reactor event bus to register a consumer for the throwable class. Unfortunately with the way that the default error handler always rethrows exceptions and the fact that it is always registered first in the event bus, no other listeners for throwable ever get called. What I have managed to do is unregister all throwable consumers, register my consumer (so it is first in line), then re-register the ones I previously unregistered. You can see this in the snippet of code below.

    val registeredConsumers =
    val unregistered = eventBus.consumerRegistry.unregister(
    eventBus.on(ClassSelector(, { ev: Event<Throwable> ->
    if (unregistered && registeredConsumers.isNotEmpty()) {
        registeredConsumers.forEach {
            eventBus.on(it.selector, it.`object`)

Has anyone encountered this problem before and have a better way of solving it? Is there a way to register a default error handler with camunda-bpm-reactor that takes precedence over the default handler? Is there another plugin that I could use or a feature of camunda I am missing?

Hi @Mark_Haley,

do you want to report every exception or only incidents?

Usually, you want only incidents. In this case, you can register a custom incident handler to create the report.

Best regards,

1 Like

Hi @Philipp_Ossler,

I want to report every exception. The solution we ended up going with is not the prototype I originally posted.
What we do now is register a custom logback appender that reports any error logs to rollbar. In general I think we can rely on well designed frameworks (like camunda and spring) to log errors properly and will work for the time being.

The incident handler will be useful for another use case we have though so thanks for sharing.

Hi Mark,

I am trying to create a similar global exception handler for camunda.

Would you please share more info on above.

I f possible would you please share above code snippet.

Hi Ashish,

We use logback for logging in our application. What I have done is added the following to my logback.xml config

<appender name="ROLLBAR" class="com.tapstream.rollbar.RollbarAppender">
<root level="WARN">
    <appender-ref ref="ROLLBAR"/>

We use camunda with spring boot. The logback site also has good documentation. Also see the github link I posted in my last reply, the readme file has almost the exact same configuration snippet I posted above.