Understanding custom incident creation behaviour

Hi Guys,

I have some queries regarding custom incident creation, lets take an example.

I have one service task which I have marked as Async before and after in modeler and in code

   public class IncidentTest implements JavaDelegate {
    public void execute(DelegateExecution execution) throws Exception {
            throw new Exception("throwing from Incident Test Task");
        }catch(Exception e){
            HFEngineFacadeInstance.facade().runTimeService().createIncident("SERVICE TASK", execution.getId(),"IncidentTest",e.getMessage() );
            throw new Exception();

Now I want to create custom incident when any failure in execution but instead it is creating incidentType as failedJob by default in incident table, how and when I should create custom incidents

When you use the createIncident() method it creates the incident, but it is non-blocking and does not cause a rollback.
When you throw your exception, you are causing a rollback / engine to stop that process. Your failed job incident should have the “throwing from incident test task” text in its message

If you want to register new incidents, you need to create a new incident handler and register it during engine startup.

take a look at this repo for a deeper example;

In your case rather than running some JS, you just want to be registering your custom incident rather than the default failedJob type. I believe most of this is non-public APIs so usage wont be the most pretty.