Example: Detecting errors within a subroutine
The following example code shows how to detect errors within the subroutine. When an error occurs, the
Err
object will contain this information and the subroutine will continue to the next statement. The example shows that the error is determined from the Number
property of the error object and the code execution path is based on this value.If no error return checking is performed after code runs and an error occurs, the code will continue. In some cases it might be appropriate to ignore errors in this manner, however this could produce undesirable results because an error could occur that could lead to other serious errors that can not be ignored.
Sub ExampleInLineErrorHandling() Dim oDisplay As DisplayClient.Display ' Set the Error handler to jump to the next line on any error. On Error Resume Next Err.Clear ' Set the display object to a display that is not loaded. Set oDisplay = Application.LoadedDisplays("Unknown Display") Select Case Err.Number Case 0: oDisplay.SetFocus Case gfxErrorConstants.gfxErrorCollectionIndex: Application.LogDiagnosticsMessage "ExampleInLineErrorHandling(): Unable to load display 'Unknown Display'", _ ftDiagSeverityError Case Else Application.LogDiagnosticsMessage "ExampleInLineErrorHandling(): Error # " _ & Err.Number & "," & Err.Description, _ ftDiagSeverityError End Select End Sub
Provide Feedback