cancel
Showing results for 
Search instead for 
Did you mean: 

How to catch general runtime exception of process executing?

joeysr20det
Champ in-the-making
Champ in-the-making
We have integrated Activiti inside our project. Currently I'm standing up a ProcessEngine in code and call the engine directly to start ProcessInstances. My question is, generally speaking, what is the proper way to catch and handle exceptions that occur during the execution of a ProcessInstance i.e. A ServiceTask is pointed to class that doesn't exist, An BPMN exception is not handled with an Error Event Handler and turns into an actual Exception. Basically, how do you catch any Exception that halts a Process during execution?

I'm familiar with creating and adding listeners to the ProcessEngine. Is there a standard way to say "let me know when anything happens to a specific running process (or to any of the running processes) that halts its (their) execution"? I need to be able to detect when a Process Instance is terminated so I can notify the owner via email with the reason why.

I've searched for several days now and can't find how.

Thanks for any pointers you can provide Smiley Happy
3 REPLIES 3

trademak
Star Contributor
Star Contributor
Hi,

Things like class not found exceptions I would not expect to happen in production, but only in development.
But other exceptions inside the execution of a service task can occur of course. The best way to handle such an exception is to catch it and sent the process execution to an error flow.
So you would have one sequence flow out of the service task in case it executed successful and another sequence flow for an error.

Best regards,

joeysr20det
Champ in-the-making
Champ in-the-making
I'm familiar with throwing BPMNError from code and catching handling them in a workflow. We just we're hoping there was some other why to tie into the process instance, on the server side when we start one, to get notified when the process dies/ends. If even without the cause so we can notify the owner so they can look into it.

I realize that runtime exceptions (not BPMNErrors (busniess process)) errors shouldn't occur, but they do happen. I know my customer will be upset when these such instances happen, because we'll have no way (that I can find anyway) to let them know when it happens.

Is there possibly a different angle I could take on this? I can't see a way to inject a handler in code to get this sort of functionality. Other than constantly polling all of the should be running instances (which I'm sure we won't be able to do due to the size of the system and userbase), I don't see a way to do this.

Any help you could give us would be grately appreciated. We've been struggling on this one for a while.

Thanks again.

frederikherema1
Star Contributor
Star Contributor
As Tijs said, if you call the "startProcessInstance" method and get NO exception, there was NO exception in executing the process from start to the first wait-state of process end. If you have async stuff, you could leverage the ManagementService to check for failing jobs… If you want instant notification of failing jobs, you can extend the JobHandler(s) for timer and async, example in Alfresco-codebase which does authentication before execution the job. You should easily surround with try-catch and do some logic on exception:

http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/repository/source/jav...