Error handling routines

G

Guest

Hello,

I made the common mistake most amateurs do - wrote a lot of sub's and
functions without considering error trapping. Now I am punished for that.

Q1: Can I have one general error handling routine for each module or must
the error handling routines be at sub or function level?

Q2: If not, is there a way to automate writing of error handling routines in
each sub? I need to write the following statements in each sub:

on error goto err_subname
....


exit_subname:
exit sub

err_subname:
.....
goto exit_subname

end sub

I am asking this of course to avoid writing the same thing hundreds of times.

Thanks
kamil
 
A

Allen Browne

Try MZ Tools - downloadable from www.mztools.com

It will add the error handling with a single click for each procedure.

BTW, you do not have to use a unique name for the label in each routine. You
can just use:
Function Test()
On Error GoTo Err_Handler

'main routine here

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, ...)
Resume Exit_Handler
End Function

If you are interested in logging the errors, see:
http://members.iinet.net.au/~allenbrowne/ser-23a.html
 
G

Guest

Thanks this was what I was looking for.
Kamil

Allen Browne said:
Try MZ Tools - downloadable from www.mztools.com

It will add the error handling with a single click for each procedure.

BTW, you do not have to use a unique name for the label in each routine. You
can just use:
Function Test()
On Error GoTo Err_Handler

'main routine here

Exit_Handler:
Exit Function

Err_Handler:
Call LogError(Err.Number, Err.Description, ...)
Resume Exit_Handler
End Function

If you are interested in logging the errors, see:
http://members.iinet.net.au/~allenbrowne/ser-23a.html
 
A

Albert D. Kallal

To be honest, there are a LOT of small little subs and routines that really
don't need error handling.

You do realize that if you distribute a mde file (which you should for
production code), then all errors are ignored, and NONE of your variables
(local, or global) get re-set when the error occurs..

So, while I do suggest that error handling is a good idea...for the "many"
zillions of little routines every where..it simply is a waste of time and
resources to put in error code for everything. Using a mde will simply
ignore these small errors...and no variables are re-set.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top