You can simply throw ProcessEngineException. (no need for the gateway in this case)
public class CustomTask1Listener implements TaskListener {
@Override
public void notify(DelegateTask delegateTask) {
try{
// your business code goes here
} catch (Exception e) {
throw new ProcessEngineException("Error!!!");
}
}
}
If you prefer to explicitly model the error then you can attach error boundary event to the task and throw BpmnError from within the task listener
https://docs.camunda.org/manual/7.15/user-guide/process-engine/error-handling/#bpmn-2-0-error-event
https://docs.camunda.org/manual/7.15/user-guide/process-engine/delegation-code/#throw-bpmn-errors-from-delegation-code