My Process Instance is always active when there is an exception occurs in my script. I would like to terminate the instance and catch exception at process instance level regardless of Script tasks/Service delegates. Could someone guide for this?
Thank you for your question. You’d need to catch the runtime error in the code and subsequently throw a BPMN Error with
throw new BpmnError("ErrorCode");
The idea being that a RuntimeException caught by the engine will create an incident and a BPMN is designed to only catch “business errors”.
And regarding terminating the instance, you might refer to Terminate end event https://docs.camunda.org/manual/7.11/reference/bpmn20/events/terminate-event/.
@StephenOTT has written the below post which is detailed enough and might be helpful in more understanding about BPMN error events.
In addition to @garima post,
For a good practice, handle the business errors using BPMN error events, in case of technical errors handle it by creating and resolving the incidents.