locked
Determine Activity that caused Exception in TryCatch Activity RRS feed

  • Question

  • Is there is a way to determine which Activity caused the exception in the Catch block of a TryCatch activity.  I looked in the Exception.Data property but did not find any additional info to help me determine which Activity threw the Exception. 

    Is there another built in mechanism in Workflow that would help me figure this out.

    Thanks,

    Phelge

    Monday, November 9, 2009 11:57 PM

Answers

  • If you want to know which is the offending activity, you will need to set up tracking (please look at the samples here %samplesRoot%\WF\Basic\Tracking; this video also will give you an overview http://channel9.msdn.com/shows/10-4/10-4-Episode-24-Monitoring-Workflow-Services/). However, please note that you won't be able to consume this data directly in your workflow.

    Leon Welicki
    Program Manager, WF


    Actually, its pretty easy to consume this in your workflow, for example you could add the WhosFaultWasThat extension below to your workflowInvoker(or app or whatever you are using), and then get information from it in your catch.

    public class WhosFaultWasThat : TrackingParticipant
    {
        public string Name { get; set; }
    
        protected override void Track(TrackingRecord trackingRecord, TimeSpan timeout)
        {
            if (trackingRecord is FaultPropagationRecord)
            {
                Name = ((FaultPropagationRecord)trackingRecord).FaultSource.Name;
            }
        }
    }

    new Catch<Exception>()
    {
        Action = new ActivityAction<Exception>()
        {
            Handler = new WriteLine()
            {
                Text = new InArgument<string>(
                  env => env.GetExtension<WhosFaultWasThat>().Name )
            }
        }
    }

    *Please note, this is the quick and dirty solution, and you would be much better of configuring the correct tracking profile rather then using the type checking, however that is a little more difficult to show as a compact solution.
    Tuesday, November 24, 2009 11:28 PM

All replies

  • The information does seem to be there as part of a FaultContext but all of this is internal so there is no way of getting at it. As far as I can tell there is no standard way to get at the offending activity. You get the stack trace but that isn't going to give you more that the offending activity class name.

    I think you best option would be to add a custom tracker so you can check what the previously executed activity is.
    Tuesday, November 10, 2009 7:50 AM
  • If you want to know which is the offending activity, you will need to set up tracking (please look at the samples here %samplesRoot%\WF\Basic\Tracking; this video also will give you an overview http://channel9.msdn.com/shows/10-4/10-4-Episode-24-Monitoring-Workflow-Services/). However, please note that you won't be able to consume this data directly in your workflow.

    Leon Welicki
    Program Manager, WF

    Tuesday, November 24, 2009 10:51 PM
  • If you want to know which is the offending activity, you will need to set up tracking (please look at the samples here %samplesRoot%\WF\Basic\Tracking; this video also will give you an overview http://channel9.msdn.com/shows/10-4/10-4-Episode-24-Monitoring-Workflow-Services/). However, please note that you won't be able to consume this data directly in your workflow.

    Leon Welicki
    Program Manager, WF


    Actually, its pretty easy to consume this in your workflow, for example you could add the WhosFaultWasThat extension below to your workflowInvoker(or app or whatever you are using), and then get information from it in your catch.

    public class WhosFaultWasThat : TrackingParticipant
    {
        public string Name { get; set; }
    
        protected override void Track(TrackingRecord trackingRecord, TimeSpan timeout)
        {
            if (trackingRecord is FaultPropagationRecord)
            {
                Name = ((FaultPropagationRecord)trackingRecord).FaultSource.Name;
            }
        }
    }

    new Catch<Exception>()
    {
        Action = new ActivityAction<Exception>()
        {
            Handler = new WriteLine()
            {
                Text = new InArgument<string>(
                  env => env.GetExtension<WhosFaultWasThat>().Name )
            }
        }
    }

    *Please note, this is the quick and dirty solution, and you would be much better of configuring the correct tracking profile rather then using the type checking, however that is a little more difficult to show as a compact solution.
    Tuesday, November 24, 2009 11:28 PM