How to continue the process when it has stopped due to an exception

I have a custom ServiceTask and need to have a way to handle error conditions that occur while processing it. The service task itself calls REST APIs.
What I have seen is when the service task throws an exception the execution halts at the previous save point.
Now what is not clear is how do I trigger the workflow forward from here so it continues to process the service task and move ahead.

@Neha_Rai If its Business validation errors you need to handle by modelling Error events.

If its technical error like Request Timeout/Gateway Timeout/Bad Request, etc, handle it by creating incidents.

To Throw BPMN Errors from Delegation Code:

public class BookOutGoodsDelegate implements JavaDelegate {

  public void execute(DelegateExecution execution) throws Exception {
    try {
        ...
    } catch (NotOnStockException ex) {
        throw new BpmnError(NOT_ON_STOCK_ERROR);
    }
  }

}

Additionally, for service tasks you can configure retry-time-cycle-configuration for service tasks.

1 Like

BPMN error works well with Boundary events on Script Task doesn’t seem to work on Service Task

I tried creating incidents as follows

IncidentContext context = new IncidentContext()
context.setActivityId(execution.getCurrentActivityId())
context.setExecutionId(execution.getProcessInstanceId())
context.setProcessDefinitionId(execution.getProcessDefinitionId())
context.setConfiguration(configuration)

IncidentEntity newIncident = IncidentEntity.createAndInsertIncident(“failedJob”,context,msg)
newIncident.getId()

I checked the database no incident entry found.

I did not find any documentation regarding this. When I checked the Camunda Java Docs I found these above APIs.Is there any other way to create it?

In Service task, you have to create incident like below:

public void execute(DelegateExecution execution) {
  try{
     //business logic implementation
  }catch(IOException ioe){
     execution.createIncident(incidentType, configuration, message);
 }
}

Hi @Neha_Rai,

it’s not written explicitly in the docs, but when you don’t handle an exception thrown in your business logic in the delegation code, you will get an incident automatically.

Just mark the service task as Asynchronous Before.

You can inspect the incident and the stack trace in the cockpit.

Hope this helps, Ingo

Just go to the cockpit and increase the number of the job tries left. This will make the job executor to execute the failed job again.