Tutorial by Examples

When a runtime error occurs, good code should handle it. The best error handling strategy is to write code that checks for error conditions and simply avoids executing code that results in a runtime error. One key element in reducing runtime errors, is writing small procedures that do one thing. Th...
Even with guard clauses, one cannot realistically always account for all possible error conditions that could be raised in the body of a procedure. The On Error GoTo statement instructs VBA to jump to a line label and enter "error handling mode" whenever an unexpected error occurs at runti...
An error-handling subroutine will either: run to the end of the procedure, in which case execution resumes in the calling procedure. or, use the Resume keyword to resume execution inside the same procedure. The Resume keyword should only ever be used inside an error handling subroutine, becau...
Often when writing a specialized class, you'll want it to raise its own specific errors, and you'll want a clean way for user/calling code to handle these custom errors. A neat way to achieve this is by defining a dedicated Enum type: Option Explicit Public Enum FoobarError Err_FooWasNotBarre...

Page 1 of 1