Resume Statement

Syntax

Resume 
Resume Next 
Resume label

Description

Used to continue program execution when an error-handling routine is complete.

Rules at a Glance

Statement Description
Resume
  • If the error-handling routine is in the same procedure as the statement that caused the error, program execution continues with the statement that caused the error.

  • If the error occurred in an external procedure called by the procedure containing the error handler, program execution continues with the statement in the procedure containing the error handler that last called the external procedure.

Resume Next
  • If the error-handling routine is in the same procedure as the statement that caused the error, program execution continues with the statement following the statement that caused the error.

  • If the error occurred in an external procedure called by the procedure containing the error handler, program execution continues with the statement in the procedure containing the error handler immediately following the statement that last called the external procedure.

Resume label
  • label must be in the same procedure as the error handler.

  • Program execution continues at the specified label.


Programming Tips and Gotchas

  • You can only use the Resume statement in an error-handling routine; otherwise, a runtime error is generated.

  • An error-handling routine doesn't necessarily have to contain a Resume statement. If the error-handling routine is at the end of the procedure, and the result of the error handling would be to exit the procedure, you can simply allow the program to execute the End Sub or End Function statement. This has the effect of both resetting the Err object and exiting the procedure. This is shown in the following simple snippet:

    Private Sub DoSomething()
    
        On Error GoTo DoSomething_Err
        ...
    DoSomething_Err:
        MsgBox Err.Description
        
    End Sub

See Also

On Error Statement
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.233.22