6 Replies Latest reply on Aug 2, 2013 7:21 AM by Sumeru Saha

    Exception Handling in jBPM

    chian Newbie

      Can any one please help me dealing with exception Handling in jBPM.

       

      I'm using a node that throws an exception. And I have a class that listens to that particular exception.

       

      But I'm having trouble to make desired transition to another node on getting an exception.

       

      So please HELP...

       

       

      Thanks in advance...

        • 1. Re: Exception Handling in jBPM
          Maciej Swiderski Master

          There are two approaches to this case (and probably even more):

          1. 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
          2. 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 Newbie

            Thank you for the reply.

             

            Actually here is the scenerio..

            processimage.jpg

            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 Newbie

              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 Newbie

                PROBLEM SOLVED...

                 

                Actually Exception Handling is not used to alter the transition...

                • 5. Re: Exception Handling in jBPM
                  Maciej Swiderski Master

                  Apologies for my comment, just noticed you asked about jbpm v3 and my comment was about jBPM5

                  • 6. Re: Exception Handling in jBPM
                    Sumeru Saha Newbie

                    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

                    ---ExceptionProcess.jpg