Resume Statement

Resumes execution after an error-handling routine is finished.

We suggest that you use structured exception handling in your code whenever possible, rather than using unstructured exception handling and the On Error and Resume statements. For more information, see Try...Catch...Finally Statement.

Syntax

Resume [ Next | line ]  

Parts

Resume
Required. If the error occurred in the same procedure as the error handler, execution resumes with the statement that caused the error. If the error occurred in a called procedure, execution resumes at the statement that last called out of the procedure containing the error-handling routine.

Next
Optional. If the error occurred in the same procedure as the error handler, execution resumes with the statement immediately following the statement that caused the error. If the error occurred in a called procedure, execution resumes with the statement immediately following the statement that last called out of the procedure containing the error-handling routine (or On Error Resume Next statement).

line
Optional. Execution resumes at the line specified in the required line argument. The line argument is a line label or line number and must be in the same procedure as the error handler.

Remarks

Note

We recommend that you use structured exception handling in your code whenever possible, rather than using unstructured exception handling and the On Error and Resume statements. For more information, see Try...Catch...Finally Statement.

If you use a Resume statement anywhere other than in an error-handling routine, an error occurs.

The Resume statement cannot be used in any procedure that contains a Try...Catch...Finally statement.

Example

This example uses the Resume statement to end error handling in a procedure and then resume execution with the statement that caused the error. Error number 55 is generated to illustrate use of the Resume statement.

Sub ResumeStatementDemo()
  On Error GoTo ErrorHandler   ' Enable error-handling routine.
  Dim x As Integer = 32
  Dim y As Integer = 0
  Dim z As Integer
  z = x / y   ' Creates a divide by zero error
  Exit Sub   ' Exit Sub to avoid error handler.
ErrorHandler:     ' Error-handling routine.
  Select Case Err.Number   ' Evaluate error number.
      Case 6   ' "Divide by zero" error.
        y = 1 ' Sets the value of y to 1 and tries the calculation again.
      Case Else
        ' Handle other situations here....
  End Select
  Resume   ' Resume execution at same line
  ' that caused the error.
End Sub

Requirements

Namespace: Microsoft.VisualBasic

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

See also