Search notes:

VBA error handling

VBA: reporting the line on which an error occurred with erl()

Error handler terminology

An error handler is neither a sub nor a function, rather, its a section of a sub or function that starts with a label.
Such an error handler is said to be enabled if it was turned on with a on error goto <label> statement.
When an enabled error handler is handling an error, the error handler is said to be active.

Error handling policy of a sub or function

A sub or function runs under a error handling policy.
The policy that is in effect when a runtime error occurs specifies how that error is handled.
VBA has five policies:
Default Stop current procedure and return the error object (err) to the calling procedure and proceed according to calling procedure's error policy.
Resume next Execute «next» statement (that is the statement that also would have executed if no error had occurred)
Goto Set current procedure's policy to default and continue at the label that is associated with on error goto.
Retry
Ignore
Terminate Behaviour is implementation defined
A sub's or function's error handling policy is changed with the on error statement.
When a function or sub is called, its policy is the Default policy, except if the sub/function is invoked from a host application, in which case it is set to Terminate.

Runtime errors

Some interesting, imho, runtime errors include
5 Invalid procedure call or argument
6 Overflow
9 Subscript out of range
10 redimensioned variable is currently locked by a byRef parameter
11 Division by zero
13 Type mismatch: declared type of redimensioned variable is variant and its value type is not an array
20 Resume without error (Encountering resume statement without error)
62 Input past end of file
91 Object variable or With block variable not set
94 Invalid pattern string
94 Invalid use of null
438 Object doesn't support this property or method
424 Object required
450 Wrong number of arguments or invalid property assignment
448 Named argument not found
449 Argument not optional
450 Wrong number of arguments or invalid property assignment

See also

The on error and the resume statements.
The VBA err object.
VBA language

Index