<

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

Basic Error Handling Tool

Published on
3,233 Points
233 Views
Last Modified:
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
Christopher Hankwembo is a Zambian Chartered Accountant and also developer of CA Premier Accounting Package
The best software application must always have an error handling tool

Introduction

An error handler is a bit of code which will do pre-defined actions whenever an error occurs. For instance, produce a message to the user or designer describing the nature of the error. For an error handler to be useful, it must provide a minimum of information in its message to the user. Below is a typical example of an error handler I use.


Professional applications need to comprise error handling to trap unexpected errors. By using a consistent error handler, you can make sure that when bangs occur, the user is properly informed and your program exits elegantly. 


Basic error handling just hides the default behavior and exits the program. Advanced error handling can include all sorts of features such as saving information about the cause of the error and the environment at the time, attempts to address the problem, and information for the user on what they need to do next.


Basic Error Handling Code

Below is my simple error handling tool, please note that this is just a basic tool, only applies to novice developers, experts may have advanced error handlers and difficult to follow:


Private Sub Form_Error(DataErr As Integer, Response As Integer)
Select Case DataErr
Case 2107
MsgBox "The value you entered does not meet the validation rule defined for the field or control", vbOKOnly + vbExclamation, "Error Number 2107"
Response = acDataErrContinue
Case 2113
MsgBox "The value you entered isn't valid for this field", vbOKOnly + vbExclamation, "Error Number 2113"
Response = acDataErrContinue
Case 2169
MsgBox "You can't save this record at this time", vbOKOnly + vbExclamation, "Error Number 2169"
Response = acDataErrContinue
Case 2237
MsgBox "The text you entered isn't an item in the list", vbOKOnly + vbExclamation, "Error Number 2237"
Response = acDataErrContinue
Case 3022
MsgBox "The changes you requested to the table were not successful this may create duplicate", vbOKOnly + vbExclamation, "Error Number 3022"
Response = acDataErrContinue
Case 3200
MsgBox "The record cannot be deleted or changed because table includes related records", vbOKOnly + vbExclamation, "Error Number 3200"
Response = acDataErrContinue
Case 3201
MsgBox "You cannot add or change a record because a related record is required in the table", vbOKOnly + vbExclamation, "Error Number 3201"
Response = acDataErrContinue
Case 3314
MsgBox "Cannot perform cascading operation on table because it is currently in use", vbOKOnly + vbExclamation, "Error Number 3314"
Response = acDataErrContinue
Case 3315
MsgBox "Zero-length string is valid only in a Text or Memo field", vbOKOnly + vbExclamation, "Error Number 3315"
Response = acDataErrContinue
Case 3316
MsgBox "please contact the developer for this kind of error it could be a Corrupt download or incomplete installation ", vbOKOnly + vbExclamation, "Error Number 3316"
Response = acDataErrContinue
Case 2105
MsgBox "You can't go to the specified record you may be at the end of record set", vbOKOnly + vbExclamation, "Error Number 2105"
Response = acDataErrContinue
Case Else
MsgBox "This is an unexpected error occurred" & DataErr & "" & AccessError(DataErr)
Response = acDataErrContinue
End Select
End Sub


Conclusion


A good error handling tool is very important if developers are to deliver a more user-friendly software.

0
Comment
1 Comment
LVL 24

Expert Comment

by:John Tsioumpris
Even at novice level since you have gathered so much error information it would be better if you had it stored in a table so that you could easily edit/update.
I really liked your Analog Clock on the form...
0

Featured Post

JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Join & Write a Comment

This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month