locked
How do I stop Exception from propagating when activity faults in ScheduleActivity RRS feed

  • Question

  • Hi,

     

    I'm trying to implement a TryCatch flowChart activity,

     

    This activity is also a NativeActivity that uses the ScheduleActivity() method to control the flow of its children activities.

     

    this TryCatch activity is the child of another flowChart NativeActivity (so actually we got 3 levels: UpperFlowChart-> TryCatch->WriteLine).

     

    Thing is that when WriteLine throws an Exception, it bubbles all the way back to the UpperFlowChart and triggers its OnActivityFaulted method.

     

    The question is: How do I catch the exception in the TryCatch Activity and stop it from bubbling further up?

     

    When an Exception occured I do reach the OnActivityFaulted() method I set when Scheduling the activity (I kinda expected some 'handled' flag at 1 of the arguments of this OnActivityFaulted() method).

     

     

    I schedule the activity (on both the upper flowChart and the TryCatch) using this overload of the ScheduleActivity() method:

    protected virtual void ScheduleActivity(NativeActivityContext context, Activity activity)
      {
       
       context.ScheduleActivity(activity, OnActivityCompleted, OnActivityFaulted);
      }
    


     

    and the OnActivityFaulted method is as such (it does nothing actually) again for both UpperFlowChart and the TryCatch:

     

    protected virtual void OnActivityFaulted(NativeActivityFaultContext faultContext, Exception propagatedException, ActivityInstance propagatedFrom)
      {
       Debug.WriteLine("propagatedException.Message = " + propagatedException.Message);
      }
    


     

    Any help will be appreciated,

    Thanks in advance.

    Eyal.


    • Edited by Quesso Levy Wednesday, August 17, 2011 2:21 PM misstypes, clarification
    Wednesday, August 17, 2011 2:18 PM

Answers

  • Try calling NativeActivityFaultContext.HandleFault() in your OnActivityFaulted() method.

     

    • Marked as answer by Quesso Levy Wednesday, August 17, 2011 4:13 PM
    Wednesday, August 17, 2011 3:25 PM

All replies

  • Try calling NativeActivityFaultContext.HandleFault() in your OnActivityFaulted() method.

     

    • Marked as answer by Quesso Levy Wednesday, August 17, 2011 4:13 PM
    Wednesday, August 17, 2011 3:25 PM
  • I must say that this is the very first thing I tried and it didn't work.

     

    It does work now though,

     

    Guess we all have to deal with computer Voodoo every now and than.

     

    Thanks alot Maurice.

     

    Eyal.

    Wednesday, August 17, 2011 4:14 PM
  • Hello,


    Please let me know in which way exactly you "throw an exception" in WriteLine activity?

    I have similar scenario in my application, and I in my child activity I am trying with:

    throw new Exception("Exception message");

    However, code execution doesn't finish in FaultCallback of try/catch activity, but it gives an error "exception was not handled in user code".

    Similarly to your case, but in fact opposite, I am sure the way I am doing now worked few days ago, in earlier stage of my development.
    But somehow, I can’t finish in FaultCallback anymore.

    Thank you,
    Predrag

    Friday, September 9, 2011 7:47 AM