Error Handler

In a huge application in most procedures and functions the error handling is done this way:

private MyProc()
on error GoTo Err_Handler
'..........
'...........
'Body of procedure or function
Exit Sub
Err_Handler:
ErrObject.OneOfMethods(Parameter)
End Sub

ErrObject is an object with many methods. ErrObject itself very often is a source for error, because either ErrObject was not created by some reason, or something wrong with parameters and so on.
Any idea, how to make Error Handling better?
Thank you.
Vlad
[589 byte] By [vchapran] at [2007-11-15 16:17:19]
# 1 Re: Error Handler
What is done here is nothing more then code-reuse, and is a good way of errorhandling. Like you said, placing it all in an object brings some chance for more errors, so placing it is a public module rather than in on object can be adviced. Another approach is placing it in an activex control, but I would advice you NOT to do this.

Centralized error handling is a good thing, that is for the end user. All error messages will look the same way, of course, for debugging purpose it can be hell, cause you will always wind up removing it to see where exactly the error was.

Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
Cakkie at 2007-11-10 0:59:02 >
# 2 Re: Error Handler
if you ar e looking for a way to have an error Handler inside the call to error
handler, you may do the following:
private MyProc()
on error GoTo Err_Handler
'..........
'...........'Body of procedure or function
Exit Sub

Err_Handler:
'save the parameters you need
'say "parameters" is declared at least on
'top of MyProc()
'...
resume TheSecondErrHandler
Exit Sub

TheSecondErrHandler:
on error goto ErrObjErrHandler
Retry:
ErrObject.OneOfMethods(Parameter)
Exit_From_Here:
Exit Sub

ErrObjErrHandler:
'here you may manage errors for your object
'(ie: re-creating it, validate parameters,
decide to resume the Exit_From_Here and do not
use ErrObj...)
select case err.Number
Case 489
'...

resume Retry:
Case else
'...
resume Exit_From_Here:
End Select
End Sub

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood,
Bruno Paris and all the other wonderful people who made and make dev-archive
a great place.
Come back soon, you Gurus.
Cimperiali at 2007-11-10 1:00:05 >
# 3 Re: Error Handler
Thank you very much
Vlad
vchapran at 2007-11-10 1:01:09 >
# 4 Re: Error Handler
...You're welcome

Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood,
Bruno Paris and all the other wonderful people who made and make dev-archive
a great place.
Come back soon, you Gurus.
Cimperiali at 2007-11-10 1:02:09 >