Siebel VB Language Reference > Methods Reference for Siebel VB > Error Handling Methods >

On Error Method


The On Error method identifies the location of code that handles an error. It does not return a value. You can also use it to disable code that handles the error. If you do not use the On Error method, and if a run-time error occurs, then Siebel VB stops running code.

Format

On Error {GoTo label | Resume Next | GoTo 0}

The following table describes that parts of an On Error statement. You can include only one of these parts.

Part
Description

GoTo label

Identifies the code that handles the error that starts at the label argument. If this label does not reside in the same procedure as the On Error statement, then Siebel VB creates an error message.

Resume Next

Identifies the code to run after handling the error. It typically identifies the code that occurs immediately after the statement that caused the error. You can use the Err statement to get the error code of the run-time error at this point in the error handling.

GoTo 0

Disables any error handler that is enabled.

Usage

Note the following:

  • If an On Error GoTo label statement references an error handler, then that error handler is enabled.
  • If an error handler is enabled, and if a run-time error occurs, then Siebel VB gives control to the code that includes this error handler. The error handler remains active from the time the run-time error is handled until code flow encounters a Resume statement in the error handler.
  • If another error occurs while the error handler is active, then Siebel VB searches for the error handler in the procedure that called the current procedure:
    • If it find this error handler, then it stops the current procedure and activates the error handler in the calling procedure.
    • If it does not find this error handler, then it searches for a handler that resides in the procedure that called the calling procedure, and so on.

      Because Siebel VB searches in the caller for an error handler, it ignores any On Error statements that exist in the original error handler.

  • Running an End Sub or End Method statement while an error handler is active creates a No Resume error. You can use the Exit Sub or Exit Method statement to end the error condition and exit the current procedure.
Example

The following example prompts the user for a drive and directory name. It uses the On Error method to handle an entry that is not valid:

Sub Button_Click
   Dim userdrive, userdir, msgtext
in1:
   userdrive = "c:"
   On Error Resume Next
   ChDrive userdrive
   If Err = 68 then
      Goto in1
   End If
in2:
   On Error Goto Errhdlr1
   userdir = "temp"
   ChDir userdrive & userdir
   userdir
   Exit Sub
Errhdlr1:
   Select Case Err
      Case 75
         msgtext = "Path is invalid."
      Case 76
         msgtext = "Path not found."
      Case 70
         msgtext = "Permission denied."
      Case Else
         msgtext = "Error " & Err & ": " & Error$ & "occurred."
   End Select      
      Resume in2
End Sub

Siebel VB Language Reference Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Legal Notices.