Exception derived type via the VB 2005 Throw keyword. Any possible incoming exceptions using the VB 2005 Try/Catch keywords and an optional Finally scope. Last but not least, I pointed out that the legacy VB 6.0 style of error handling.
This code sample shows a simple way of expected exception handling for Visual Basic programs, similarly the Try-Catch statement in VB.net.Supported Visual Basic versions:
- Visual Basic 4, 5, 6
- Visual Basic for Aplications (VBA): Excel, Access, Word, Outlook, PowerPoint, Publisher, Visio, AutoCad, etc.
- VBScript
Advantages:
- structured (no Goto jump), consistent and clear programming way to catch expected exceptions
- cooporates with traditional procedure-level error trapping to handle unexpected run-time errors
- not required variable declarations
- can be copied or moved freely in the source code
- can be nested (Try block in Try block)
- supports recursive algorithms
- exception handling is outside of the 'On Error Resume Next' scope
- hotkeys to insert Try-Catch block, Resume-Next block and Debugger template
- ease and safe of use by a smart COM Add-In to insert code snipets
- absolutely free
Restrictions:
- Unfortunately there is no Finally clause (just like in C++).
- After the 'On Error Resume Next', only one statement can be used in the error testing section (between 'On Error Resume Next'and'.Catch').
If you want to use more statements to handle unexpected run-time errors, then you can use the traditional error handling with the 'On Error GoTo' statement (download samples). - VBScript: the 'Case 0' clause is required when 'Case Else' clause is used because the 'Is' keyword is not impelemented in the Select-Case statement in VBScript.
Download... (Includes samples and free portable VB6-VBA COM Add-Ins with source code, etc...)
- License: Freeware
- COM Add-In version: 1.100517
- Size: 277 KB
- Release Date: May 18, 2010
- Author: Robert Einhorn
What's new: