Resume Command

Purpose

Resumes execution after an error-handling routine is finished.

Syntax

Resume [Next | 0 | label ]

Description

The Resume statements can only be used in an error-handling routine defined with On Error GoTo.

The Resume or Resume 0 are identical and (should) re-execute the line that caused the error. The Resume [0] command is useful when the error trap can fix the error situation. The program may retry to execute that line again and might continue without errors. However, Resume [0] doesn't work and generates an exception.

Resume Next (should) resume executing with the line immediately following the line that caused the error. However, Resume Next doesn't work and generates an exception. Resume Next command is only meaningful with On Error Resume Next.

The only working Resume statement is Resume label. Execution resumes at the label specified in the required argument. The label argument is a line label or line number and must be in the same procedure as the error handler. Actually, this is nothing else than GoTo label. The only difference is that Resume label re-initializes the On Error trap. Any new error following the label is catched in the same error trap, which might cause an infinite loop when an error occurs.

Inside the error trap the On Error mechanism is disabled.

Example

ResumeStatementDemo()

Close # 1

Kill "TESTFILE"

 

Sub ResumeStatementDemo()

On Error GoTo errtrap

Open "TESTFILE" for Output As # ' Open file for output.

Kill "TESTFILE"   ' Attempt to delete open file.

labelx:

Exit Sub

errtrap:

MsgBox Err.Number & Err.Description

Resume labelx

End Sub

Remarks

A Resume [ Next | 0 ] command instructs the compiler to create code to hold the current executing line (4 bytes per line for subroutines smaller than 250 lines, and 7 bytes for larger routines). The code to maintain the position is generated between On Error GoTo label and On Error GoTo 0 or the error trap staring with label. It seems the compiler generates faulty code for this process and halts with an exception.

On Error Resume Next instructs the compiler to generate optimized Try/Catch code around each code line (8 bytes extra per line). To prevent code bloat, you better use Try/Catch.

See Also

On Error, Try

{Created by Sjouke Hamstra; Last updated: 22/10/2014 by James Gaite}