Coding for Activity Errors

To help troubleshoot workflow errors, we recommend that you wrap Anthology activities in a TryCatch activity and use the ValidationMessageCollection property wherever it is available.

ValidationMessageCollection

Almost all Anthology activities provide the ValidationMessageCollection property. This property is designed to detect and log .NET framework and WCF service call exceptions as well as parameter validation exceptions.

ValidationMessageCollection provides built-in arguments.

  • In Forms Builder workflows, the argument to use is:

    formInstance.validationMessages

  • In eventing workflow for Anthology Student or CampusNexus CRM, the argument to use is:

    args.validationMessages

In eventing workflows you can also specify the variable of type "Cmc.Core.Eventing.ValidationMessageCollection" (see Capture Validation Errors).

ValidationMessageCollection does not need to be newed up (i.e., a new ValidationMessageCollection is not needed for the Default value). The property value will only be newed up if it is null; otherwise is it appended to previous captured validation messages.

TryCatch

Anthology activities should be wrapped in a TryCatch activity to handle exceptions that are raised at run time. This applies primarily to activities that write to the database (i.e., Save and Update activities). Lookup and Create activities do not need to be embedded in a TryCatch activity.

The TryCatch workflow activity has three sections: Try, Catches, and Finally.

Try

Place the Anthology activity for which you want to provide error handling in the Try section. Our example uses a ConvertApplicantToEnrollment activity. The Try section successfully completes if no exceptions are thrown from it.

Catches

Select the exception type in the Catches section. In our example the type is System.Exception. You can add multiple catches where each catch handles a different exception type. System.Exception is the catch-all exception and should always be the last exception in the list if you want to trap specific exceptions, otherwise more specific exceptions will never be caught. Catches cannot be reordered. They must be deleted and added in the correct order.

trycatch_catches_exceptions

After selecting the exception type, you can add an activity to the catch. In our example a WriteLine activity writes exception messages to the console.

"Exception: " & exception.Message

Note: WriteLine activities are useful when testing workflows with the Run option. Otherwise, use LogLine activities with Level=Error.

The Catches section successfully completes if no exceptions are thrown from it.

Finally

The Finally section includes a Condition that checks if the ValidationMessageCollection has errors. The Condition in our example uses a variable named "valMsgColl" of type "Cmc.Core.Eventing.ValidationMessageCollection".

If an error is found, a WriteLine activity writes the text "Validation messages" to the console.

The ForEach activity ensures that invalid values in any field of the ConvertApplicantToEnrollment activity will result in a validation message, e.g.:

Validation messages
Student Id is not valid
Validation messages
Invalid Academic Advisor selected

The console will also display a message if an exception is caught, e.g.:

Validation messages
Validation Failed: Field: ProgramVersionId generated an exception during validation.
The following errors were encountered while processing the workflow tree:
'DynamicActivity': The private implementation of activity '1: DynamicActivity' has the following validation error: Value for a required activity argument 'GradeLevelId' was not supplied...

The activities in the Finally section are executed when either the Try section or the Catches section successfully completes.

 

    TryCatch withConvertApplicantToEnrollment

For more information, see: