Error Handling Technique ?

G

Guest

Is there anything wrong with this error handling technique?

public sub SomeSub()
on error goto ErrSS
'code goes here
exit sub
ErrSS:
err.clear
end sub

I like to make small functions/subs that do one task so I don't care about
resuming anyway. As long as I "clear" the error, do I need to "resume"
anywhere. It seems like waste to me when so many examples, including the
code generated by access wizards, resume only to an exit sub/function command.

Thanks,
Cliff
 
G

Guest

It's really up to you. Some people think you should only have one exit point
from a sub or function. When you have small subs/functions there isn't really
much confusion about where you're exiting, it's pretty obvious (just my
personal opinion). I do it the same way you did in your example - have the
OnError goto a label, with that label at the end of the routine with an exit
just before for the code above it, and my error notification code as the last
statement(s) with an implicit exit. But you should have some sort of
notification about the error, either a msgbox or log it to a table, something
so that you know the error occurred.

Jim B
 
T

Tim Ferguson

There is often a need to put suitable clean up code in the finishing part:
public sub SomeSub()
on error goto ErrSS
'code goes here

ExitSS:
myRecordSet.Close
Set myObjectVariable = Nothing
Resume ExitSS
' Error is cleared anyway with a Resume call
' so the next line is redundant
 

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