Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Global OnError Statement?


Message #1 by "Lyon, Mark H ERDC-ITL-MS Contractor" <Mark.H.Lyon@e...> on Thu, 15 Aug 2002 19:37:59 -0500
I agree with Andy. It is very difficult to make a global
error handling, because every method needs a different handling.
But what you can do is to have a common logging method, I use
this tecnique and it works remarkable well.

Put in a .bas module a method like 

Public Sub HandleError( _
                oErr As ErrObject, _
                moduleName As String, _
                logMessage As String)

and call it in all the error handling in your code, like:

Sub MyMethod()
 on error got errsub
 '' code here
 exit sub
errsub:
 HandleError err, "MyModule:MyMethod", "Log this message"
 ' your error handling here
end sub

(you can also write a small addin to do it automatically)
In the HandleError you can descide what to do, and you have
one only place to modify in case you change idea.
You can also add a 'severity' to the error, and you can read
a severity threshold from the registry when the app starts,
and in the HandleError you can do different things based on
the severity and the severity threshold (like display or log
all errors with severity greater than 12)
If a customer has a problem, you can change this severity to
add more information. You can also decide to email directly
to you from the HandleError method.

How does it sound? I am sorry, we have to live with the VB
limited error handling...

Marco

  Return to Index