Why did this error event not trigger

My idea is to trigger this errorEvent when serviceTask throws an exception

This is my java code

I only set one start listener. Now there’s a question that when the serviceTask throws an exception,
the errorEvent is not triggered

error

Hello my friend!
Welcome to Camunda Community! \o/

You can use a try/catch in your java delegate to catch the error that occurred, and handle this exception by throwing new BpmnError.

in BpmnError the first parameter is the Global Message Reference that you must place in your Error Boundary Event, and the second parameter is any additional message that you want to send to inform the error that occurred. In the example below, I just took the Exception message that occurred, and threw this same message into Camunda through BpmnError.

public class TestDelegateCode implements JavaDelegate {
    @Override
    public void execute(DelegateExecution execution) throws Exception {
        try {
             your logic code here!
            }
        } catch (Exception e) {
            throw new BpmnError("GlobalErrorReferenceName", e.getMessage());
        }
    }
}

I hope this helps!

William Robert Alves

1 Like

It worked, thank you :blush:

1 Like

I’m glad to have helped!
When you need something, don’t hesitate to call us here on the forum!

Please mark the answer that solved your problem as “Solution” to conclude this topic and so that other users can quickly find the answer they are looking for when they need it.

Thanks in advance!

William Robert Alves

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.