Handle exception in service task

How to handle exception in task that is asynchronous - service task? I have tried with try and catch but it doesn’t work. I assume that job executor handles the exception but how can I see the stack trace because I need somehow to debug and read the exception message?

P.S. I have also checked the ACT_HI_JOB_LOG table and it’s empty.

Thank you in advance.

You can create incident if any exception. And also you can refer the below link for more error handling strategies.

Error-Handling in BPMN

@aravindhrs how can I create incident? When I surround my all code in try and catch the service never ends in catch block but it tries to retry the previous service delegate.

if the service task is marked as async, then job executor will retry for number of retries configured in bpmn. after all the retry attempts completed with unsuccessful, it will log exception if the exception caught in catch block

It should be possible to create and resolve incidents through public API.

* RuntimeService API

runtimeService.createIncident(String incidentType, String executionId, String activityId, String configuration) runtimeService.resolveIncident(String incidentId)

* DelegateExecution

execution.createIncident(String incidentType, String configuration) execution.resolveIncident(String incidentId)

* REST api enhancements
  create resolve / incidents through REST api as well.

It retries many times but I can’t see exception…

Why does try-catch not work? The job executor does not catch the exception before that, as it is higher up in the call stack.


@thorben that’s what I’m trying to solve. After few analysis I saw that job executor has default wait timeout to 5 minutes and after that it fails (retries again), so my exception wouldn’t be called (I don’t know why). I have increased wait timeout to 15 minutes and that solve my problem.