Re: Is David Fenton right about error handling? (re-post?)
- From: "Anthony England" <aengland@xxxxxxxxxx>
- Date: Tue, 3 Jan 2006 22:41:53 +0000 (UTC)
"Randy Harris" <randy@xxxxxxxxxxxx> wrote in message
news:XDBuf.45667$7h7.44831@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> "David W. Fenton" <XXXusenet@xxxxxxxxxxxxxxxxxxx> wrote in message
> news:Xns97409DD3B8A3Df99a49ed1d0c49c5bbb2@xxxxxxxxxxxx
>> "Anthony England" <aengland@xxxxxxxxxx> wrote in
>> news:dpe8kt$cag$1@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:
>>
>>
>> However, I had an app that had problems that could only be explained
>> by the use of On Error Resume Next. When those were removed (or
>> allowed to apply to only one line at a time), the problems with data
>> errors being lost disappeared. This was several years ago.
>>
>> Now, philosophically, I have a definite problem with relying on it.
>> It's lazy programming, in my opinion.
>>
>>
>> > Do others have experience of this happening?
>> > It seems he would prefer version 2. But I am wondering - if I
>> > cannot rely on the error handling to be reset when I exit my
>> > function, can I guarantee there is zero possibility of an error in
>> > the Exit_Handler part in version 2? (e.g. the recordset wasn't
>> > nothing, but trying to close it causes an error). If there is an
>> > error in the Exit_Handler part, we obviously get stuck in a
>> > never-ending loop, so to some extent it would make sense to make
>> > sure that this cannot happen. The code is also less verbose,
>> > particularly when there are many objects to be cleared up.
>> > Perhaps the answer is version 3 which tacks on a final 'On Error
>> > GoTo 0' but I have never seen anyone write a function with that
>> > type of error handling.
>>
>> I don't know what errors could happen in closing a recordset. If you
>> are avoiding doing it my way because of a worry about an unforeseen
>> error, then it seems to me to be contradictory of your seeming
>> preference for a method that ignores *all* errors, anticipated or
>> not. In other words, you seem to prefer a method that ignores *all*
>> unforeseen errors to a method that may break if *one* unforeseen
>> error occurs.
>>
>> That seems extremely unwise to me.
>>
>> --
>> David W. Fenton http://www.dfenton.com/
>> usenet at dfenton dot com http://www.dfenton.com/DFA/
>
> I had a problem similar to the one David describes with On Error Resume
> Next. It was particularly bad because I let it get out to a customer that
> way (shame on me). It caused some highly intermittent problems that were
> extremely difficult to pin down. It was several years ago and I no longer
> have the code.
>
> I also agree that its use is "lazy programming" but I still use it on
> occasion. Properly trapping errors is always better, but I'm a lazy
> programmer. The solution that I've come up with is to never, ever leave a
> section of code with On Error Resume Next "unterminated". I consider On
> Error Goto 0 (or Goto something else) a proper termination. I used to put
> Err.Clear ahead of the Goto, but that didn't seem to make any difference.
> Also, keep blocks of code with Resume Next as small as possible and be
> very
> certain that code that doesn't get run and doesn't generate an error can't
> cause problems elsewhere. This "solution" has worked well for me.
>
> --
> Randy Harris
> tech at promail dot com
> I'm pretty sure I know everything that I can remember.
Hi Randy. Thanks for the response. Your mention of Err.Clear prompted me
to re-read the help file which clearly states that the method is called
after the Exit Function. But I guess if you couldn't rely on one, then you
couldn't rely on the other.
' ==================================================
' ====== Acc XP Help File ===============================
Clear Method
Clears all property settings of the Err object.
Syntax
object.Clear
The object is always the Err object.
Remarks
Use Clear to explicitly clear the Err object after an error has been
handled, for example, when you use deferred error handling with On Error
Resume Next. The Clear method is called automatically whenever any of the
following statements is executed:
Any type of Resume statement
Exit Sub, Exit Function, Exit Property
Any On Error statement
Note The On Error Resume Next construct may be preferable to On Error GoTo
when handling errors generated during access to other objects. Checking Err
after each interaction with an object removes ambiguity about which object
was accessed by the code. You can be sure which object placed the error code
in Err.Number, as well as which object originally generated the error (the
object specified in Err.Source).
.
- Follow-Ups:
- Re: Is David Fenton right about error handling? (re-post?)
- From: Randy Harris
- Re: Is David Fenton right about error handling? (re-post?)
- References:
- Is David Fenton right about error handling? (re-post?)
- From: Anthony England
- Re: Is David Fenton right about error handling? (re-post?)
- From: David W. Fenton
- Re: Is David Fenton right about error handling? (re-post?)
- From: Randy Harris
- Is David Fenton right about error handling? (re-post?)
- Prev by Date: Re: Is David Fenton right about error handling? (re-post?)
- Next by Date: Programatically accessing "object groups"
- Previous by thread: Re: Is David Fenton right about error handling? (re-post?)
- Next by thread: Re: Is David Fenton right about error handling? (re-post?)
- Index(es):
Relevant Pages
|