To cause a procedure to handle relatively simple runtime errors without branching to a separate error-handling routine, you can use a form of the On Error statement that lets you deal with errors "in line"; that is, directly in the code that caused the error, rather than in a separate routine.
This example checks for errors when saving a 3270 or 5250 session document.
If the save operation fails, an error message appears. If the save operation succeeds (Err.Number returns 0), a "Save complete" message appears. This macro was written to require the error handler; without it, the macro terminates with an error if the SaveSettings method fails.
Sub SaveSessionDemo()
Dim theError As Integer
On Error Resume Next
ThisIbmTerminal.Save
theError = Err.Number
Select Case theError
Case 0
MsgBox "Save complete."
Case Else
MsgBox Err.Description & "."
End Select
End Sub