Example: Simple error handling within a subroutine
The following example code shows a simple error handler for a subroutine. When an error occurs, the code jumps to the
ErrHandler:
label, the error is logged to FactoryTalk Diagnostics and code resumes at the line after the one that caused the error. This example will always report when an error occurs, but does not report which line caused the error.Sub ExampleSimpleErrorHandling() ' Set the Error handler to jump to the ErrHandler: label on any error condition. On Error GoTo ErrHandler Dim oDisplay As DisplayClient.Display ' Set the display object to a display that is not loaded. Set oDisplay = Application.LoadedDisplays("Unknown Display") ' code will continue to run because the Resume Next statement was called, ' but will also have an error since the variable oDisplay was not set. oDisplay.SetFocus Exit Sub ErrHandler: ' Simply log the error message and continue Application.LogDiagMessage "Error occurred in ExampleSimpleErrorHandling()." & _ "Error# " & Err.Number & ", " & Err.Description, _ ftDiagSeverityError Resume Next End Sub
Provide Feedback