Results 1 to 4 of 4

Thread: <on-exit> and exception handling

  1. #1
    Join Date
    Aug 2004
    Posts
    1,072

    Default <on-exit> and exception handling

    Let's say that I have a state that looks a little something like this:

    Code:
    <view-state id="A">
      <transition on="condition1" to="B" />
      <transition on="condition2" to="C" />
      <transition on="condition3" to="D" />
      <on-exit>
        <evaluate expression="someService.someAction()"/>      
      </on-exit>
    </view-state>
    Here I have a state that could end up transitioning to one of 3 other states. But regardless of where I head off to next, I need to always invoke someService.someAction()...that's why it's in <on-exit>.

    Fine...but what if someService.someAction() throws an exception? In that case I'd like to transition to "E"...so I change the state to this:

    Code:
    <view-state id="A">
      <transition on="condition1" to="B" />
      <transition on="condition2" to="C" />
      <transition on="condition3" to="D" />
      <transition on-exception="SomeException" to "E" />
      <on-exit>
        <evaluate expression="someService.someAction()"/>      
      </on-exit>
    </view-state>
    And this is where it all goes pear-shaped. As I transition away from "A", an exception is thrown from someService.someAction(). That triggers the on-exception transition...which is a transition away from "A", which means that the <on-exit> block is executed. someService.someAction() still throws an exception, which triggers the on-exception transition...which is a transition away from "A", which means...

    You get the picture.

    I read elsewhere that it is recommended to let exceptions be handled in the service and to have the service return an event for SWF to transition from. I agree with that...but not sure that it helps me here because I'd end up with the same scenario, only without the exceptions.

    Any idea how I can make this work?
    Last edited by habuma; Oct 28th, 2009 at 02:47 PM.

  2. #2
    Join Date
    Nov 2008
    Posts
    742

    Default

    It's redundant, but can you put your on-exit expression inside each of the transitions instead? This should let your on-exception transition work properly.

  3. #3
    Join Date
    Aug 2004
    Posts
    1,072

    Default

    That would work except that I left out one little detail (for simplicity's sake...I didn't think it would matter at the time)...

    Some of those transitions are defined in a parent state and are inherited by a handful of other states. The following snippet better illustrates the scenario I'm looking at:

    Code:
    <view-state id="#SOME_SECTION">
      <transition on="condition2" to="C" />
      <transition on="condition3" to="D" />
    </view-state>
    
    <view-state id="A" parent="#SOME_SECTION>
      <transition on="condition1" to="B" />
    
      <transition on-exception="SomeException" to "E" />
      <on-exit>
        <evaluate expression="someService.someAction()"/>      
      </on-exit>
    </view-state>
    
    <view-state id="Z" parent="#SOME_SECTION>
      <transition on="condition1" to="B" />
    
      <transition on-exception="SomeException" to "E" />
    </view-state>
    Here, I need to call someService.someAction() whenever/however I transition away from "A". But I do *NOT* need to call it when transitioning away from "Z".

    I suppose that I could create multiple parents (one with and one without the on-exit), but that is a bit uglier than I would've liked.

  4. #4
    Join Date
    Nov 2008
    Posts
    742

    Default

    Remember, transition elements are merged, they don't override.

    You can redefine all of the inherited transitions in state "A" and place your evaluate expression in each of the transitions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •