AnsweredAssumed Answered

Exception is not received from runtimeService.startProcessInstanceByKey()

Question asked by yevgenyl on Jun 20, 2018

In our application we have a case where when running new process, using runtimeService.startProcessInstanceByKey(), if there will be an exception in this process - it is not bubbled up.

 

To be more specific:

 

We’re starting to run process1:

class RunProcess1

{  

      @Inject   

      private RuntimeService runtimeService;    

 

       public void run()  

       {         

         try{                

                 runtimeService.startProcessInstanceByKey("process1", paramMap);         

          }         

          catch(Exception e) {

              doSomething();         

          }  

      }

}

 

One of the service tasks of process1 starting to run another process - process2:

 

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();        

              }   

       }

}

 

 

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.

Can you help?

 

Outcomes