cancel
Showing results for 
Search instead for 
Did you mean: 

Flow global exception handler

coconuts11
Champ in-the-making
Champ in-the-making
Hello,

I'm looking for an object able to catch any uncaught exception anywhere in the diagram.

This object will be responsible in doing a last resort operation before leaving the flow (I would like to avoid a try-catch block in which there is the starting of the flow, I would like to stay inside the flow).

Do you know if something like a "global exception handler" exists in Activiti ?

I first looked at listeners but it seems that there is no event like an "uncaught exception event". Moreover, I inspected the code (I sent a NullPointerException in my code) and I notice that Activiti rethrows the exception (I don't see any hook where I could put a piece of code to do my last resort operation).

I would really appreciate your help,
Thanks.
5 REPLIES 5

trademak
Star Contributor
Star Contributor
When using an event sub process you could define a error start event to catch error events on a global level. Catching Java exceptions on a global level is not something we support. But often other solutions can be chosen instead. Is your use case for service tasks or also for other task types?

Best regards,

coconuts11
Champ in-the-making
Champ in-the-making
Thanks you very much for your reply.

I already use error start event in different use cases, and that's ok but it implies that you have in every ServiceTask a try/catch on Exception, and then throw the end error event.
This use case may be suitable for service task, even if try/catching Exception in every of them will then be mandatory to trap any exception.

However, I would like to not rely on this behaviour because I would also like to be able to trap exception that could occur because my diagram fails.
For instance we may have a gateway with 2 branches, on first branches we test if (for instance) the "transition" variable equals to "OK", and on the second if it equals to "KO". Finally, if we set the "transition" variable to another value different from "OK" or "KO" then an exception will be raised (I tested that use case).

Typically, this is the kind of problem I would like to recover properly (instead of having the exception thrown to the caller).

jbarrez
Star Contributor
Star Contributor
Im not following 100% here, what exactly is it you don't want to do?
Even if you do a try catch in the service task logic, you would still get regular exceptions from process execution

coconuts11
Champ in-the-making
Champ in-the-making
thanks for your reply.
what do you mean by "regular exceptions from process execution" please ?
Bad configuration in diagram for instance ?
In fact, I would like to be able to manage any exception that can occur (even those which are not in my code/ServiceTask).
For instance, in spring-web there is an object "ResponseEntityExceptionHandler" which is able to manage any exception (just by annotating a method with a mapped exception like Exception.class you always are able to return a custom response to the HttpClient)

thanks

jbarrez
Star Contributor
Star Contributor
> what do you mean by "regular exceptions from process execution" please ?

Database errors. Java logic error if you don't try-catch them.

Currently, beyond try-catching every Activiti call you do, there is not much you can do.