qb45advr.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
ON ERROR Statement Details
  QuickSCREEN      Details      Example      Contents      Index
──────────────────────────────────────────────────────────────────────────────
ON ERROR Statement Details
 
Syntax
  ON ERROR GOTO line
 
The line argument is the line number or line label of the first line
in the error-handling routine. This line must appear in module-level
code.
 
If line cannot be found in the module where the error occurred,
or if there is no ON ERROR GOTO statement, a backward search
is made through the modules that invoked the module with the error.
If an active error handler is found, it is used. If no active error
handler is found, an error message is printed and program execution
halts. The specific error message depends on the type of error.
 
Only modules in the invocation path are searched. Modules outside
the path are not searched, even if there is no active error handler
in the search path.
 
A line number of 0 disables error handling. It does not specify line 0
as the start of the error-handling code, even if the program contains
a line numbered 0. Subsequent errors print an error message and halt
the program. Once error handling is enabled, any error that can be
trapped causes a jump to the specified error-handling routine.
 
Inside an error handler, executing an ON ERROR statement with a line
number of 0 halts program execution and prints the error message for
the error that caused the trap. This is a convenient way to halt a
program in response to errors that cannot be processed by the error-
handling routine.
 
Note that an error-handling routine is not a SUB or FUNCTION procedure
or a DEF FN function. An error-handling routine is a module block of
code marked by a line label or line number.
 
SUB and FUNCTION procedures and DEF FN functions can contain their own
error handlers. The error handler must be located after the last
executable statement but before the END SUB, END FUNCTION, or END DEF
statement. To keep the error handler from executing when there is no
error, the procedure or function must terminate with an EXIT SUB, EXIT
FUNCTION, or EXIT DEF statement immediately ahead of the error
handler, as in the following example:
 
SUB InitializeMatrix (var1, var2, var3, var4)
      .
      .
      .
   ON ERR GOTO ErrorHandler
      .
      .
      .
   EXIT SUB
 
   ErrorHandler:
      .
      .
      .
   RETURN
 
END SUB
 
  Note: Errors occurring within an error-handling routine are not
        trapped. These errors halt program execution after printing
        an error message.