Excel VBA Error Handling & Debugging Flashcards
7 cards from real Excel VBA practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 7 Excel VBA Error Handling & Debugging flashcards as text
What is the effect of using 'On Error GoTo 0' in a VBA procedure?
Answer: Disables any currently active error handler in the procedure
'On Error GoTo 0' disables the currently active error handler, causing VBA to revert to its default unhandled-error behavior for any subsequent errors.
What does the Err.Number property return when no error has occurred in VBA?
Answer: 0
When no error has occurred, Err.Number returns 0, which is why 'If Err.Number <> 0' is the standard pattern for detecting whether an error happened.
Which error handling approach is most appropriate for production VBA code that needs to respond differently to multiple error types?
Answer: Use a GoTo handler with a Select Case block on Err.Number
A GoTo error handler with a Select Case on Err.Number lets you apply specific logic per error type, resulting in robust and maintainable error handling.
What is 'error propagation' in VBA?
Answer: An unhandled error bubbling up the call stack to the calling procedure
Error propagation occurs when a procedure has no error handler (or re-raises the error), causing the error to move up the call stack to the calling procedure.
What is the correct syntax to raise a custom user-defined error in VBA?
Answer: Err.Raise Number, Source, Description
Err.Raise allows you to generate a custom error by specifying an error number, source, and description, enabling custom error signaling within procedures.
Which range of error numbers is reserved for user-defined errors raised with Err.Raise in VBA?
Answer: 512 to 65535
VBA reserves error numbers 512 through 65535 for user-defined errors; numbers below 512 are reserved for VBA's built-in runtime errors.
Which pattern ensures cleanup code (like closing files or releasing objects) always runs even if a runtime error occurs in VBA?
Answer: Use a GoTo to an exit label for normal flow plus Resume to the same exit label from the error handler
Placing cleanup at an exit label, using GoTo to reach it from normal flow, and using 'Resume ExitLabel' from the error handler ensures cleanup always executes — VBA's equivalent of a 'finally' block.