Question/Problem
Is it possible to log the display name of the activity where an error occurs within a “Try Catch”?
Resolution
Three methods can be considered:
■ Method 1: Global Exception Handler
The steps are as follows:
- In the Ribbon, select the “Design” tab and choose “New” > “Global Handler” to create a global exception handler by entering a name.
- In the global handler workflow, an argument called “errorInfo” is automatically generated. Please check the argument panel.
- By specifying “errorInfo.ActivityInfo.Name” in activities like “Log Message”, you can log the name of the activity that threw the exception.
For reference: Global Exception Handler
Relevant section: Global Exception Handler
Studio - Global Exception Handler
— Excerpt —
“Use the ActivityInfo property of errorInfo to obtain the name of the activity that threw the exception and display it in the [Output] panel.”
■ Method 2: Using “Try Catch” + “Invoke Workflow File” to utilize “exception.Source”
In the configuration where “Invoke Workflow File” is placed in the “Try” of “Try Catch” and catches exceptions that occur in the called workflow in the “Catches”, the display name of the called activity may be stored in “exception.Source”.
The steps are as follows:
-
Place “Invoke Workflow File” in the “Try” of “Try Catch” to call a separate workflow for the process you want to detect errors.
-
Specify the type of exception (e.g., System.Exception) in the “Catches”. By default, exceptions can be referenced with the name “exception”.
-
Specify “exception.Source” in activities like “Log Message”.
Regarding this behavior, the official guide states as a technical limitation that “the source may vary when an exception occurs within the called workflow”, and it is not explicitly stated that the display name of the activity will always be stored.
For reference: Try Catch
Relevant section: [Examples of Using the Try Catch Activity]
Activities - Try Catch
— Excerpt —
“Due to technical limitations, when an exception occurs within the invoked workflow, the source of the exception reported in the Try Catch scenario may differ.”
The limitations are as follows:
- It is limited to exceptions that occur in the target of the “Invoke Workflow File” and does not retrieve the display name of activities placed directly in Main.xaml.
- There have been reports of “exception.Source” containing values other than the activity display name, such as “System.Activities”, and the behavior may differ depending on the version of Studio and execution form (executing from Studio / executing after publication).
For reference: Exception.Source is displayed as System.Activities
Exception.SourceがSystem.Activitiesと表示されてしまいます
If you adopt Method 2, it would be appreciated if you could check in advance if the expected display name can be retrieved with your version of Studio and actual execution form.
■ Method 3: Using “Try Catch” + “Assign” to manually retain the activity name
If you do not use a global exception handler and only target some activities on Main.xaml, you can manually store the activity name in a variable.
The steps are as follows:
- Create a string type variable to store the activity name.
- Place an “Assign” activity just before each activity you want to target and specify the variable from step 1 as the “left side (To)” and the corresponding activity’s display name as the “right side (Value)”.
- In the “Catches” of the “Try Catch”, log the variable from step 1.