-
1. Re: Exception Handling in jBPM
swiderski.maciej Aug 1, 2012 8:47 AM (in response to chian)There are two approaches to this case (and probably even more):
- model your exception handling in the process, so whenever something wrong happen you will trigger an error event and then model catch error event that will handle exception flow in the process - in my opinion this is recommended so business process covers all scenarios and not only positive flow so to say
- enhance your work item handlers to deal with exception and signal events that are awaiting error situations
Both most likely will provide you with same result but option 1 in my opinion is clearer as that is visible directly on the process level and not somewhere in the code.
HTH
-
2. Re: Exception Handling in jBPM
chian Aug 1, 2012 11:40 PM (in response to swiderski.maciej)Thank you for the reply.
Actually here is the scenerio..
Here, when node1 throws the exception, it should traverse through transition error.
Here is the processdefinition.xml
<?xml version="1.0" encoding="UTF-8"?>
<process-definition xmlns="urn:jbpm.org:jpdl-3.2" name="VitWork">
<start-state name="Start">
<transition to="node1"></transition>
</start-state>
<node name="node1" async="true">
<event type="node-leave">
<action class="com.sample.action.MessageActionHandler1"></action>
</event>
<transition to="node2" name="ok"></transition>
<transition to="Error Handling" name="error"></transition>
</node>
<node name="node2" async="true">
<event type="node-leave">
<action class="com.sample.action.MessageActionHandler2"></action>
</event>
<transition to="Approve"></transition>
</node>
<task-node name="Approve">
<task name="Approve"></task>
<transition to="end"></transition>
</task-node>
<task-node name="Error Handling">
<task name="Error Handling"></task>
<exception-handler exception-class="java.lang.Exception">
<action class="com.sample.exceptionHandler.ExceptionHandler"></action>
</exception-handler>
<transition to="end-state1"></transition>
</task-node>
<end-state name="end"></end-state>
<end-state name="end-state1"></end-state>
</process-definition>
Here is the MessageActionHandler1.java
package com.sample.action;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;
public class MessageActionHandler1 implements ActionHandler {
private static final long serialVersionUID = 1L;
public void execute(ExecutionContext context) throws Exception {
System.out.println("Thread 1 going to Sleep for 15 seconds...");
throw new Exception("Dummy Exception");
}
}
-
3. Re: Exception Handling in jBPM
chian Aug 1, 2012 11:41 PM (in response to chian)Actually I'm confused with this portion:
<exception-handler exception-class="java.lang.Exception">
<action class="com.sample.exceptionHandler.ExceptionHandler"></action>
</exception-handler>
So please help..
I need to go to node "ERROR HANDLING" on throwing an exception by "node1"
-
4. Re: Exception Handling in jBPM
chian Aug 3, 2012 10:42 AM (in response to chian)PROBLEM SOLVED...
Actually Exception Handling is not used to alter the transition...
-
5. Re: Exception Handling in jBPM
swiderski.maciej Aug 4, 2012 12:04 PM (in response to chian)Apologies for my comment, just noticed you asked about jbpm v3 and my comment was about jBPM5
-
6. Re: Exception Handling in jBPM
sumerus Aug 2, 2013 7:21 AM (in response to chian)Hi Maceij,
We're trying to perform some exception handling in our process. What we have is Script Task 1, Use Task1, ScriptTask2, ScriptTask3 (in order) ... in ScriptTask1 i'm setting a process variable (say, someVar) to some value before landing into the UserTask1. I can see the process variable value refelected in the portal screen. In Script Task2, i'm again setting variable to a different value and finally in ScriptTask3 a java.lang.NPE is thrown. What we observe is that the value of the someVar still has the first value which was set in ScriptTask1 and the value set in ScriptTask2 is rolled back (which is a desired behavior on exception). But the problem is that now the instance is stuck at the ScriptTask3. How do I route this instance into an exception flow or an alternate so that some corrective step can be taken either manually or systematically and the instance can be salvaged.
Please help with ur valuable suggestion.
Thanks
Sumeru