cancel
Showing results for 
Search instead for 
Did you mean: 

ErrorBoundaryEvent error handling java

activ_user
Champ in-the-making
Champ in-the-making
Hi,

I am new to Activiti and trying to create process contains several service task and user task.

I would like to know if there is possibility in activiti to handle exception occured in my service task and depending on the result execute different user task? It means, if service task (java class implemented JavaDelegate) throw Exception, I would like to handle this exception and execute user task "System error handling" where I'll have two or more choice, first - end of my process, second - for example, retry my service task or any different task. In other case if exception isn't occured, skip "System error handling" and do next task.

In user guide is something like "ErrorBoundaryEvent", I used this boundary event for my service task but isn't working and I don't know why, maybe isn't possible in this case? (my example process diagram and java class below)





public class Example implements JavaDelegate {

    public void execute(DelegateExecution delegateExecution) throws Exception {
        try {
            /**
             *
             * My logic
             *
             */
        } catch(Exception e) {
            throw new BpmnError("Error code", e.getMessage());
        }

    }
}

[img=640x480]http://s8.postimg.org/o8dk6vv7p/diagram.png[/img]

Is it good solution? maybe is there different way to solve this problem?

Thanks for advice.

4 REPLIES 4

activ_user
Champ in-the-making
Champ in-the-making
Can anybody help me?

jbarrez
Star Contributor
Star Contributor
No, it won't work the way you describe. You have to catch the exception in your service task, and put process variables into the process instance, using that in the exclusive gateway to route.

activ_user
Champ in-the-making
Champ in-the-making
Do you think I should do this by JavaDelegate or ActivitiBehavior? What is the difference? I understand I have to do somethink like this:

[img=640x480]http://s24.postimg.org/b6feyt9ed/activiti_example.png[/img]

trademak
Star Contributor
Star Contributor
The BpmnError code you mentioned in your earlier post should work fine. It is possible to throw a BpmnError in your JavaDelegate and catch it in an error boundary event. You have to make sure that the error code you throw exactly matches the one mentioned in your error boundary event. Or you can keep the error code in the error boundary event empty and then it catches every bpmn error. If this is not working for you, please share a unit test showing the issue.

Best regards,