Handling Errors with the On Error Resume Next Statement

The On Error Resume Next statement is useful when performing inline error handling. This statement is the only error handling statement the toolkit supports. On Error Resume Next does not clear the Err object, so you can use inline error handling to display a meaningful error messages rather than displaying the generic Application Error message.

The following is an example of an inline error handling routine:

Private Sub Command1_Click()
   On Error Resume Next
   Dim N, D
   N = InputBox("Please enter a number to divide by:", "FractionMaker")
   D = 1 / N
   If Err = 0 Then
      MsgBox 1 / N, vbOKOnly, "1 / " & N
   Else
      MsgBox Err.Description, vbExclamation, "Error: " & Err
   End If
End Sub

The following are possible errors you could handle using this routine:

You could handle each error separately based on the Err.Number property.

For more information on error handling, see Debugging Your Code and Handling Errors your Visual Basic 5.0 Books Online documentation.