How to retrieve the "Reason" of a terminated workflow?

I have a workflow which calls another workflow. When the child workflow encounters specific exceptions, it will terminate the workflow with a relevant message set up in the “Reason” field.

I have a Try Catch to catch the WorkflowTerminatedException, how can I retrieve the “Reason” from the terminated workflow?

Hi,

Attached an example (TerminationTest calls ExceptionTest which throws a WorkflowTerminatedException).
In short:
(pretend WTE_Exception is a caught WorkflowTerminatedException)
WTE_Exception.message will show the Reason
WTE_Exception.innerException will let you access an exception passed in the Exception argument to the Terminate Workflow activity.

Please note that WorkflowTerminatedException can only be caught one (or more) levels up in the invoke chain.

As a sidenote:
In a setup like yours it would be a good practice to put the exception that caused the termination (the caught SelectorNotFoundException exception) as the Exception argument to TerminateWorkflow activity, to have it accessible upper in the call chain. Otherwise it’s an equivalent of swallowing the actual exception and throwing a new one, which is not recommended in general, as it makes debugging harder - the actual selector that was not found is never logged.
In a standard logging sequence there’s usually at least 5 elements found (window/browser, username, password, submit button, one element in a screen after logging to confirm it passed), any of them can fail and you’re not logging which of them did.
If you don’t want to pass it higher up for some reason, the message of it should at least be logged using LogMessage activity (level warning or higher, depending on your practices). That way you don’t need to run to see what happened, it’s already in the logs.

ExceptionTEst.xaml (8.9 KB)
TerminationTest.xaml (6.6 KB)

3 Likes

Hi andrzej,

Thanks a lot. This is exactly what I am after.

I want to terminate the workflow without message box. Currently I am getting message box after terminatation.I want to terminate or stop the flow at specific time. How can i do that?