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.
Note: This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Attachmate provides this sample code "AS IS" with no warranties.
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