Error Handler (Global?)

  • Thread starter Thread starter David
  • Start date Start date
D

David

Hello All

I have been using local error handlers for some time now and for the first
time I have something that I feel I need to add as a global error i.e. a way
to handle database connectivity failure.

I thought about global error handlers and have read a few things on them.
All articles seem to be devoted to EITHER local OR global.
Is there anything wrong, programatically, with using both?

I currently use
On error goto err_???

err_???:
select case err.number
case ???
Dothis

Case else
Error MSG

I was thinking of putting a global handler into case else instead of
defaulting directly to an error message. I believe this will give me ability
to handle global errors easily without extra programming but flexibility to
handle local exceptions.

Thanks for your input
David
 
Technically, the ERROR HANDLER can only be local as in

On Error Goto Err_MySub

Exit_MySub:
Exit sub

Err_MySub:
Code:
However, there's nothing stopping you from calling a global sub in the error
routine. I've moved toward doing just that so that I can capture each and
every error along with the source of the problem and a few other things. The
external sub takes a couple of parameters and then inserts a new record into
a logging table. If the nature of the sub is such that it needs something
custom then i go that route as a relinker sub most likely would.
 
Here's an example that I think is close to what you are asking for:
Error Handling in VBA
at:
http://allenbrowne.com/ser-23a.html

It suggests a generic error handler you call from each procedure. The
generic handler suppresses certain messages, provides custom messages for
others, and logs the error messages so you can call them later.

You might also like to consider adding this utility:
http://www.mztools.com/v3/mztools3.aspx
This gives you a toolbar button in your VBA window, so a single click adds
the error handler to the current procedure.
 
Back
Top