|
Visual Basic automatically adds a form of error handling to your application which is good for developers, but not for end users. If an error occurs during a procedure your app will come with a message with error code and description, allowing the user to Debug or End. In the following I show what your error handling options are and how our Code VB centralised error handler will give you an excellent feedback about errors.
Add Error HandlingYou can either add error handling using the builder to make a procedure, or you can add it afterwards using from the menu: Alt-CEA. Use Alt-CEA[down-arrow] to open the combo box to show the full list to select the preferred errorhandler from. The menuCode-vb builders let you select the appropriate error handling. In the Code-VB menu you will find under the 'Error' entry entries to speed up error handling.
When considering error handling we have to match the possible error situations with the available error handling options: 1. Simple property Let/Get situation. - no error handling
I am quite certain we don't need error handling here. What could go wrong with assigning a string to a string variable? |
VB default error message. We don't want users to see this!
. |
If your code does nice things like changing the status bar or setting hourglasses or disabling controls that are not critical to the main process you may decide in case of error you don't want to bother the user with minor errors.
Supports a common technique of transferring control to section with code dedicated to handling the error:
If this is chosen additionally the module basErrorHandle with centralized error handling procedure ErrorHandle is inserted.
The well-known example here is of course trying to read a file. You may only hope it is there. There is a whole set of related and similar errors and handling them is probably something you want to do in the procedure in which the error occurs (e.g. retry/cancel), not in the centralized error handler.
OK, you probably know a better way. No problem, you can create your own error handling fragment using the Fragment Editor. As long as you store it in the \Fragments\ErrorHandlers subfolder it will automatically be added to the selection list.
The best way to have errors handled is allowing users send you an email when the error occurs, automatically, with all relevant details (what error number, which procedure and line, additional info) included. This type of automated feedback let's you know how well your programs behave with minimum effort. You will get this reporting behaviour whenever you use Procedure Builder with default error handling.

The centralized error handling module is stored in \vbcode\ErrorHandlers\basErrorHandle.bas. You may choose to change it or make an alternative handler module and refer to that in dialog Settings / Files and Folders.
It is a common practice to make available not only the error info, but also where the error occurred. For this automatically Module and procedure name strings are added if they are needed. Again the name of these strings can be customized in the Settings dialog. If you add line numbers you can even identify which line the error occurred.
To add line numbers:
To remove line numbers:
The fast way to add debug statements:
