[Incidents] Creating incidents

Hi,

With Java Service Task, i want control exceptions and show theirs stacktrace in Cockpit.

For exemple, in my Service Task 1 i have null pointer exception, i can catch exception in other task but not creating incidents in the thrower task, i dont have the red “1” in Service Task , So i could not see the exception stacktrace in the Cockpit . Below is the Model and the Code

incidents.bpmn (4.2 KB)
Thanks.

@Override
public void execute(DelegateExecution delegateExecution) throws Exception {
    try {
        System.out.println("ProcessReques1 is called ");
        String s = null;
        s.toLowerCase();
    } catch (Exception e) {
        //delegateExecution.getProcessInstance().createIncident("500", "error occurs"); // THIS DOSE NOT WORK
        throw new BpmTecnicalException("504", "my error messsage");// This works
    }
}

you should be able to do deletegateExecution.createIncident(...). WHen you do this, it will be non-blocking (from last i checked); this means it will create the incident, but it will not cause the task to “stop and rollback”.

If you want to stop the task/rollback and throw a incident, you can just throw a java exception.

Hello , this does not solve my problem

  • when i tried this code :

    @Override
    public void execute(DelegateExecution delegateExecution) throws Exception {
    try {
    System.out.println(“ProcessRequestDelegate1 is called “);
    String s = null;
    s.toLowerCase();
    } catch (Exception e) {
    delegateExecution.createIncident(”-1”,“c”);
    }

the two process are completed without problem (Service 1 et 2)

  • when i tried this code :

    @Override
    public void execute(DelegateExecution delegateExecution) throws Exception {
    try {
    System.out.println(“ProcessRequestDelegate1 is called “);
    String s = null;
    s.toLowerCase();
    } catch (Exception e) {
    delegateExecution.createIncident(”-1”,“c”);
    throw e ;
    }
    I the process can not be started (With REST API i got error)

  • finally i tried this code :

    @Override
    public void execute(DelegateExecution delegateExecution) throws Exception {
    try {
    System.out.println(“ProcessRequestDelegate1 is called “);
    String s = null;
    s.toLowerCase();
    } catch (Exception e) {
    delegateExecution.createIncident(”-1”,“c”);
    throw new BpmnError(“error”);
    }
    }

In this case : the error is caugth in the “E” task, ok , but there is no incident created in service 1
so exception could not be shown

Thks

If your exception is throw as part of the transaction that started the process instances then the process instance won’t start because of the roll back. See the Camunda transaction docs.

If you create incidents and your process completed then yes you won’t see any errors.

A simple test for you is set async before on the start event if the process and re try with the version where you throw a exception. You also don’t need to do the create incident method if you are throwing the exception.