-----Original Message-----
Joel-
FWIW- I tend to agree with Graham, there should never be
unhandled errors. Inasmuch as some code *should* never
cause an error, these are usually inconsequential bits
that can be handled with on error resume next. The
example you cited *should* never cause an error, but what
if (and I don't know) an error is triggered if there are
no items in the list, or the control is not visible? I
think it's better to handle an error by saying 'aw, I
don't care' than to give an ugly, meaningless (to the
user) message to that poor user. (Users are not always
poor, programmers almost always are ;-)
Remember that the user is ALWAYS going to screw up your
code. When you're testing, you *know* what is supposed to
go in a field, and you put it there to make sure your
code works, unfortunatly, users tend to be unkind and put
silly things in forms (i.e. "My ex-wife sucks" in the due
date field). You can validate and handle these things,
but its good to also have a catch all error handler, even
for simple stuff, to take care of anything you didn't
think of. I can't tell you how many times I left out an
error handler and spent a lot of time walking code to
figure out that something silly F'ed the whole thing up.
Anyway, sorry to be long winded, but I guess I've become
a bit passionate about error handling. I think I need a
hobby.
Ben
-----Original Message-----
Hi Joel
My philosophy is that you should NEVER have an unhandled error. You may
decide that the probability of an error occurring is zero, in which case you
might take the risk of omitting an On Error statement, but you must
recognise that it *is* a risk.
You may decide that you want to ignore any error which occurs, by using On
Error Resume Next. This is fine, especially in a short, inconsequential
procedure. However, this still constitutes error handling. It's just that
the action taken by the handler is to ignore the error and continue to the
next statement.
--
HTH!
Graham Mandeno [Access MVP]
Auckland, New Zealand
Return mail address is invalid in a vain attempt to reduce spam.
Feedback is welcome at: (e-mail address removed)
Please post new questions or followups to newsgroup.
I'll open this up for debate: How do you determine whether
you should include error handlers in a procedure? Should
error handlers be included in code such as:
Private Sub VendorCode_GotFocus()
'Purpose: Autodrop the Vendor Code field if enabled.
Me!VendorCode.Dropdown
End Sub
Does a single line of code, or two or three lines of code
warrant error handlers? Is there some other criteria for
determining if some can be left out?
I'm sure everyone has different opinions on this. I'm
interested in hearing different points of view.
Thanks!
.
.