Trapping Run-time Errors

Often you can anticipate the types of run-time errors users will encounter and shield them from these errors by including error-handling code, also known as error trapping, in your application.

An error handler is a routine for trapping and responding to errors in an application. You enable an error handler by using the On Error statement. Because the language for the toolkit is based on VBScript, the only error handling statements available are On Error Resume Next and On Error Goto 0.

The most efficient way to use these statements to trap errors is to perform in-line error handling, the process of checking for errors immediately after each line of code that may cause an error.

    To perform in-line error handling

  1. Place On Error Resume Next at the beginning of a code segment that may generate an errors.
  2. Examine the Err object after each statement to determine if an error has occurred.

    The Err object contains the error number and description as well as the source of the error.

After each error notification, execution resumes with the next line of code. To turn off in-line error handling, use the On Error Goto 0 statement.