Exiting an error handler

You must exit an error handler with the RESUME LABEL statement.  Execution branches immediately to the specified local label, and the original error trap operation is restored ready to catch the next run-time error.

In the sample program, you want to use RESUME to a specific line.  Put the line label before the line that requests user input to give the user another chance to enter a correct path.

Here is the sample program, complete with Error Trapping:

SUB GetFileNames(File() AS STRING)

  DIM CurrentDir AS STRING

  DIM fName AS STRING, Mask AS STRING

  DIM X AS INTEGER

  ON ERROR GOTO ErrorTrap

  Mask = "*.*"

  CurrentDir = CURDIR$

 

GetPath:

  Path  = AskUserForPath$()

  fName = DIR$(RTRIM$(Path) + Mask)

  IF LEN(fName) = 0 THEN EXIT SUB

  X = 1

  WHILE LEN(fName)

    Files(X) = fName

    fName = DIR$

    INCR X

  WEND

  EXIT SUB

 

ErrorTrap:

  SELECT CASE ERRCLEAR

    CASE 53   : ErrorMsg "No files in this directory."

    CASE 71   : ErrorMsg "Drive not ready."

    CASE 76   : ErrorMsg "That path doesn't exist."

    CASE ELSE : ErrorMsg "Unknown error!"

  END SELECT

  RESUME GetPath

END SUB

 

 

See Also

Error Overview

Error Trapping

How error traps work

Setting an error trap

Writing an error handler

Error Trapping Summary