|
|
Better Error Handling
2. Don't really care - on error resume nextIf 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. 3. Error occurs which can't be ignored - On Error GoTo HandleErrorSupports 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. 4. I expect an error here! - On Error GoTo HandleSelectCaseThe 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.
5. No, I want to handle differently! - Do it yourselfOK, 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. Error reporting using mailThe 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.
Customizing the centralized error handling procedureThe 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. Locating errors module and procedure name stringsIt 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. Add / remove line numbersTo add line numbers:
To remove line numbers:
Add debug statementsThe fast way to add debug statements:
|