Solved

Error Handling component

Posted on 1998-08-27
5
183 Views
Last Modified: 2010-04-30
We're just about to launch a large VB SQL Server project.
we would like a comprehensive way of handling errors with 'humane' messages.  Surely this has already been created and there is a component that we can purchase out there.  Granted, there will be a need to alter some of the user messages, depending on what the user is doing...Who has a component based error handler??
0
Comment
Question by:martinodea
5 Comments
 
LVL 4

Expert Comment

by:mcix
ID: 1431501
When you say component, do you mean OCX, DLL or just a set of classes that you would implement yourself?
0
 
LVL 3

Expert Comment

by:OmegaJunior
ID: 1431503
Greetings, martinodea,

To complement CoRpSe's comment, I use two kinds of error handling.
1) when I know the code should execute, error or no error:

On Error Resume Next

the Code

If Err then
          Select Case Err
                    Case SomeNumberYouAlreadyKnow
                               strMsg = "MyVeryOwnErrorText"
                     Case Else
                               strMsg = Err.Description
           End Select
           MsgBox strMsg, vbOKOnly, "NameOfCodeAsString: " & Err.Number, _
               Err.HelpFile, Err.HelpContext
End If

2) If I know the code must not be executed on error:

On Error Goto CodeNameAsStringFault:

the Code

CodeNameAsStringFault:
If Err then
          Select Case Err
                    Case SomeNumberYouAlreadyKnow
                               strMsg = "MyVeryOwnErrorText"
                     Case Else
                               strMsg = Err.Description
           End Select
           MsgBox strMsg, vbOKOnly, "NameOfCodeAsString: " & Err.Number, _
               Err.HelpFile, Err.HelpContext
End If

As you can see, the structure of the error handling is the same, only the exact moment the code jumps into error handling is different. Use MsgBox to come up with your own messages.

Imagine!
0
 
LVL 9

Expert Comment

by:cymbolic
ID: 1431504
I've found it valuable for everybody to just filter out some errors and keep on running.  For instance, I do a lot of migration systems, and frequently get duplicate key input into a table.  rather than reacting to each of these (I mean it's in there already, how many times you gotta write the thing!), I merely count them and report at the end of the process that nn duplicates were ignored.

Also, since you often get voluminous repetitrive crap in each error message, I have a routine that strips out all the redundant verbiage and shows only the significant discriminating text in the message.  Beyond that, since you often get the same error over and over again in a long process, I save the last error, and report to the user, so and so error followed by the identified cases that fell in that category, just to keep the volume down and not to overly alarm the user.  

Finally, I log the SQL that was involved in the error in a file, so that if an error causing condition can be fixed in a database, the actual file of SQL can be reprocessed, and all recoverablel operations get applied without rerunning the whole process.  Often this is as simple as bringing the file up in the ISQL Query program or in Enterprise Manager and running it as an SQL script.

In VB, you get so many cases of on error cascading hairballs, that you most often have to pick up your reponse logic from studying the actual error patterns your particular configuration of process and garbage in data provoke.
0
 
LVL 1

Expert Comment

by:sdbanks
ID: 1431505
I found this error handling method for use in access.  

http://www.wji.com/access/b7174.html

or

If you are looking for an expensive package. Aion, from Platinum Technologies,   has a tool that lets you define your business rules in a "rules database".

0
 
LVL 1

Accepted Solution

by:
mithomas earned 100 total points
ID: 1431506
I think you're asking for an "engineered" approach, rather than one having tons of msgbox code spread throughout the system.  Good for you!  Regardless of the build/buy decision, you're going to have to invest some time and effort if you want a truly engineered approach.

I don't know of a component that you can buy that will handle the "presentation" of your errors, though I've designed a couple of OO approaches.  However, there are a couple of products that will at least update your code to contain error handlers.  One is VBRig (can't remember the company).  The other is FailSafe from NuMega (www.numega.com).  From memory, it seems that FailSafe is the better engineered product.

For reporting the errors, you basically want to pass off the "presentation" of the error to a global function (or preferably a method in a class) that handles presenting the error.  Presentation is defined as how the error gets to the user.  You may want a VB-style message box, your own message box, or even to write to a file, etc.  Think this through.  Routing errors to an external function or method is a good way to allow your error presentation to change without affecting any other code.

You might also want to consider wrapping the raised error itself into an object.  This allows you to capture the original error, and to add your own info to it, such as an error level, extra descriptive text, etc.  You'd then pass this object to your presentation handler when the error is raised.

If you're doing component development, we found that it was useful to "relay" some errors as opposed to "raising" them.  For example, if we received a VB-generated error, we'd "relay" it in our error object, passing along the original VB info as well.  If it was a business rules violation, then we'd raise an exception.  The COM client would then catch the error and display the appropriate error presentation.

Mike Thomas
Digital Answers, LLC
www.digitalanswers.com
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem to delete range 4 54
VBA to copy paste columns form one file to other 20 78
Adding to a VBA? 6 48
How does CurrentUser work? 10 25
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now