6 Replies Latest reply on Mar 24, 2009 9:42 PM by Ronald van Kuijk

    Exception-Handler an Transitions

    Thomas Hamacher Novice

      Hi @all,

      I am calling an Action in a transition as followes

      <state name="state1">
       <event type="node-enter" >
       <action class="state1ActionHandler" name="request"></action>
       <transition name="state change" to="isCancelled" ></transition>
       <transition name="invoice" to="invoiced" >
       <action class="InvoicingActionHandler" name="invoice"></action>

      As there might occur an Exceptions the InvoicingActionHandler I defined a "global" exception-handler

      <exception-handler >
       <action name="reroute node" class="ProcessFailedExceptionActionHandler" />

      This exception handler is perfectly called and I set the token to the source node of the transition.

      public class ProcessFailedExceptionActionHandler implements ActionHandler {
       private static final Logger log = Logger.getLogger(ProcessFailedExceptionActionHandler.class);
       public void execute(ExecutionContext executionContext) throws Exception {
       Node sourceNode = executionContext.getTransitionSource();
       Throwable throwable = executionContext.getException();
       log.info(String.format("Caught exception %s. Re-routing to source node: '%s'", throwable.getMessage(), sourceNode.getName()));
       final Token token = executionContext.getToken();

      Unfortunately the code of the action handler defined as "node-enter"-ActionHandler of the target-node is still called, although I re-route the node manually and it should not enter the initially target node anymore. Is there a way to prevent this behaviour?


        • 1. Re: Exception-Handler an Transitions
          Thomas Hamacher Novice

          Appendix to my previous post:

          Furthermore I just realized, that the transition to the initially target-node is still executed and the process goes to its initial target node and not in the manually rerouted node. So this works also not as expected as the initial target node should not be reached in any case, if an exception occured, that will be handled by my ExceptionHandler.

          Any ideas?


          • 2. Re: Exception-Handler an Transitions
            Joram Barrez Master

            See http://docs.jboss.com/jbpm/v3/userguide/processmodelling.html#exceptionhandling

            Note that the exception handling mechanism of jBPM is not completely similar to the java exception handling. In java, a caught exception can have an influence on the control flow. In the case of jBPM, control flow cannot be changed by the jBPM exception handling mechanism.

            • 3. Re: Exception-Handler an Transitions
              Brad Davis Novice

              What is meant by:

              In the case of jBPM, control flow cannot be changed by the jBPM exception handling mechanism.

              It seems that this is almost directly contradicted in the next statement in the document:

              Note that in an action that handles an exception, it is possible to put the token in an arbitrary node in the graph with Token.setNode(Node node).

              Can someone please clear this up for me?

              • 4. Re: Exception-Handler an Transitions
                Ronald van Kuijk Master

                No, it is clear (to me ;-))

                If you handle the exception IN your actionhandler, it is normal java exceptionhandling and you can put the token anywhere. If you do not handle it in your actionhandler, it it 'bubbles up' to the engine and a specified error handler can handle it or the engine handles it. In both latter cases you cannot put the token anywhere.

                • 5. Re: Exception-Handler an Transitions
                  Brad Davis Novice

                  Ronald, maybe I am wrong, but it is talking about your Action within the <exception-handler> moving the exception to an arbitrary node. But before that, it states:

                  In the case of jBPM, control flow cannot be changed by the jBPM exception handling mechanism.

                  I guess its saying that in Java, you can have nested exceptions, and the thread execution will move to whatever point the exception is caught. In other words, JBPM does not move its token automatically to like a global exception handler... it just executes a script or action within a given exception handler. It is the responsibility of the action within the exception handler to actually move the process to another node.

                  No, it is clear (to me ;-))

                  What are you saying no about? Clearing it up?

                  • 6. Re: Exception-Handler an Transitions
                    Ronald van Kuijk Master

                    ok, for the 'intimi': I stil had to respond BEFORE going to sleep.


                    No, it is clear (to me ;-))

                    is 'vague' because I'm a non-native English speaker.. ahh no, it was just vage.. sorry. I combined the answer to the first and second question...

                    now the real response

                    (01:11:56) Me, Myself and I: one thing... I do not understand your response about exceptionhandling
                    (01:12:16) bradatamentra: i was saying i didnt get your response
                    (01:12:19) bradatamentra: either
                    (01:13:11) Me, Myself and I: The action in the exception-handler is the exception..... meaning that in THAT kind of exceptions you cannot put the token anywhere. I should have mentioned that if that is what you mean
                    (01:13:55) Me, Myself and I: and yes... nested exceptions between the java code and the engine are not possible
                    (01:14:11) bradatamentra: so the action handler in my exception-handler
                    (01:14:15) bradatamentra: why cant that move the process?
                    (01:14:21) bradatamentra: or it can?
                    (01:14:33) bradatamentra: gosh, i dont get it... i have read that section of docs many times
                    (01:14:39) Me, Myself and I: no it can't afaik... because you are on a different level
                    (01:14:43)] bradatamentra: just trying it for the first time this week on client side
                    (01:15:26) Me, Myself and I: compare it to starting a program from a shell script. If the program throws an error, you are back in your shell script and cannot influence the program anymore since it 'crashed'
                    (01:16:23) bradatamentra: i just think the doc is a bit contradictory. it says you cant at first, but you can.... i dont understand why you couldnt since you could get the root token and move it to a given node
                    (01:17:11) bradatamentra: i figured what they were saying is in jbpm, the exeception handling doesnt mean the actual token is moving into the global exception handler... but just that the actions would be applied from the global exception handler to the token at the point the exception occurred
                    (01:17:38) bradatamentra: and in that sense, the flow of control is not working like it does in java.... where you can use the scope of the exception to determine flow control
                    (01:18:18) bradatamentra: instead they are saying you could use an action to determine flow control, but otherwise no flow control changes are made for handled exceptions
                    (01:19:29) Me, Myself and I: Yes in that sense it sounds contradictory... but your analysis is good

                    And yes, that was 1.19:29 local time... 1 hour before the chat ended and even then it took me 20 minutes to cut/paste this response... should have started from scratch

                    If it is still not clear, please comment