<

Basic Error Handling Tool

Published on
3,089 Points
89 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 22

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

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Join & Write a Comment

With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A query can call a function, and a function can call Excel, even though we are in Access. This is Part 2, and steps you through the VBA that "wraps" Excel functionality so we can use its worksheet functions in Access. The declaration statement de…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month