This example demonstrates how you can display a standard error message. Error handling should be added to each workflow script that you write, because errors that are not detected by the workflow code can cause the user's browser to crash.
The user-defined function PrintError receives the name of the calling procedure as a parameter. If an error has occurred, PrintError prints out the error number, description and severity, and the name of the procedure in which the error occurred.
You do not need to create an Err object, because it is intrinsic to VBScript. For details about the Err object, refer to the Microsoft documentation.
Sub PrintError(strFunctionName) If Err.Number <> 0 Then MsgBox "Error #" & Err.Number & ": " & Err.Description, _ vbOKOnly+vbCritical, _ "Workflow Error in Function " & strFunctionName End If End Sub
The following code segment illustrates how you can add error handling to your subroutines.
Sub <sub_name>() On Error Resume Next ... [Your code here] ... PrintError "<sub_name>" End Sub
The following code segment illustrates how you can add error handling to your functions.
Function <function_name>() On Error Resume Next ... [Your code here] ... PrintError "<function_name>" End Function