Exception is not bubbled up from Activiti process

We are using Activiti BPMN diagrams to run our workflows.
We’re starting to run process1 by:

class RunProcess1
{
   @Inject
    private RuntimeService runtimeService;

    public void run()
   {
          try{
              runtimeService.startProcessInstanceByKey("process1", paramMap);
          }
          catch(Exception e)
          { 
              doSomething();
          }
   }
}

The issue is that if there is an exception thrown in process2 from one of it’s services tasks, then it is not bubbled up to MyServiceTask.
I tried to throw in process2 a RuntimeException or a BpmnError exception, but it still didn’t bubbled up.
The weird thing is that the eception is thrown only after process1 is finished.
Meaning the exception is caught in catch block of RunProcess1 and not in MyTask.

Just to make it clear, exception is thrown from process2, but as it is not bubbled up to process1, so process1 continues to run as usual and only when it finish the run, the exception from process 2 will be thrown from runtimeService in RunProcess1.

How to solve it?

public class MyServiceTask implements JavaDelegate
{

    @Inject
    private RuntimeService runtimeService;

    public void execute(DelegateExecution context) throws Exception
    {
         try{
               runtimeService.startProcessInstanceByKey("process2", paramMap);
         }
         catch(Exception e)
         {
            doSomething();
         }
    }
}

Did you try running this on Flowable? Many changes have gone into the engine and behaviour might be different.
Can you post your test processes? The service tasks are not marked as async?

The service tasks are not marked as async.
I created an example for the problem:
process MyProcess1 with one service task - MyServiceTask1.
process MyProcess2 with one service task - MyServiceTask2.
MyServiceTask1 is starting MyProcess2.
I’m throwing an exception in MyServiceTask2.

The exception coming from MyProcess2 is not bubbling up to catch block in MyServiceTask1, but the exception is caught in the catch block of StartingMyProcess1.

All XMLs and classes below.

The xml of MyProcess1:

    <?xml version="1.0" encoding="UTF-8"?>
    <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
      <process id="myProcess1" name="My process 1" isExecutable="true">
        <startEvent id="startevent1" name="Start"></startEvent>
        <endEvent id="endevent1" name="End"></endEvent>
        <serviceTask id="myServiceTask1" name="My Service Task 1" activiti:delegateExpression="${myServiceTask1}"></serviceTask>
        <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="myServiceTask1"></sequenceFlow>
        <sequenceFlow id="flow2" sourceRef="myServiceTask1" targetRef="endevent1"></sequenceFlow>
      </process>
      <bpmndi:BPMNDiagram id="BPMNDiagram_myProcess1">
        <bpmndi:BPMNPlane bpmnElement="myProcess1" id="BPMNPlane_myProcess1">
          <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
            <omgdc:Bounds height="35.0" width="35.0" x="200.0" y="280.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
            <omgdc:Bounds height="35.0" width="35.0" x="590.0" y="280.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="myServiceTask1" id="BPMNShape_myServiceTask1">
            <omgdc:Bounds height="55.0" width="105.0" x="330.0" y="270.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
            <omgdi:waypoint x="235.0" y="297.0"></omgdi:waypoint>
            <omgdi:waypoint x="330.0" y="297.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
            <omgdi:waypoint x="435.0" y="297.0"></omgdi:waypoint>
            <omgdi:waypoint x="590.0" y="297.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
        </bpmndi:BPMNPlane>
      </bpmndi:BPMNDiagram>
    </definitions>

The xml of MyProcess2:

    <?xml version="1.0" encoding="UTF-8"?>
    <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
      <process id="myProcess2" name="My process 2" isExecutable="true">
        <startEvent id="startevent1" name="Start"></startEvent>
        <endEvent id="endevent1" name="End"></endEvent>
        <serviceTask id="myServiceTask2" name="My Service Task 2" activiti:delegateExpression="${myServiceTask2}"></serviceTask>
        <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="myServiceTask2"></sequenceFlow>
        <sequenceFlow id="flow2" sourceRef="myServiceTask2" targetRef="endevent1"></sequenceFlow>
      </process>
      <bpmndi:BPMNDiagram id="BPMNDiagram_myProcess2">
        <bpmndi:BPMNPlane bpmnElement="myProcess2" id="BPMNPlane_myProcess2">
          <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
            <omgdc:Bounds height="35.0" width="35.0" x="260.0" y="270.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
            <omgdc:Bounds height="35.0" width="35.0" x="640.0" y="270.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="myServiceTask2" id="BPMNShape_myServiceTask2">
            <omgdc:Bounds height="55.0" width="105.0" x="410.0" y="260.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
            <omgdi:waypoint x="295.0" y="287.0"></omgdi:waypoint>
            <omgdi:waypoint x="410.0" y="287.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
            <omgdi:waypoint x="515.0" y="287.0"></omgdi:waypoint>
            <omgdi:waypoint x="640.0" y="287.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
        </bpmndi:BPMNPlane>
      </bpmndi:BPMNDiagram>
    </definitions>


    public class StartingMyProcess1 
    	
        @Inject
    	private RuntimeService runtimeService;

    	@Override
    	public void startProcess()
    	{		
    		try
    		{
    			runtimeService.startProcessInstanceByKey("myProcess1");
    		}
    		catch(Throwable e)
    		{
    			throw e;
    		}
    	}

    }


public class MyServiceTask1 implements JavaDelegate
{
	private static final Logger logger = LoggerFactory.getLogger(MyServiceTask1.class);
	
	@Inject
	private RuntimeService runtimeService;
	
	
	@Override
	public void execute(DelegateExecution execution) throws Exception 
	{
		
		try
		{
			runtimeService.startProcessInstanceByKey("myProcess2");
			logger.info("Running myProcess2 succeeded.");
		}
		catch(Exception e)
		{
			logger.info("Exception in myProcess2.");
			throw e;
		}
	}

}


    public class MyServiceTask2 implements JavaDelegate
    {

    	@Override
    	public void execute(DelegateExecution execution) throws Exception 
    	{
    		throw new RuntimeException("For Testing!");	
    	}

    }