Re: Robert Craig... One Wish Please

new topic     » goto parent     » topic index » view thread      » older message » newer message

At 10:29 31/07/02 -0400, you wrote:
<snip>
>The issue is really whether we trap the error before it occurs with
>hundreds of lines of error-checking code, or do we trap it after it
>occurs with hundreds of lines of error-handling code?  The cleaner
>method is to trap the error before it occurs.
<snip>

I totally agree that is the cleaner approach.

I generally write short programs (less that 500 lines and many much
shorter) for my purposes (I'm from a system admin background) but even so
I'd say between 30 percent and even 60 percent of the lines of code I write
are some form of error checking, error reporting and, if possible, error
correction.

If you know a condition might exist that could cause future program flow to
fail then check for it, if it exists then try and correct it and if
"normal" processing cannot continue then raise an alert and either back off
(if in a batch/unattended environment) or ask the user (if in an
interactive environment) for an opinion on how to proceed.

Of course you don't know what all the possible errors could be.  For medium
and larger sized programs it is impossible (humanly) to predict all
combinations of logic flow so unexpected errors might and do occur.  In my
mind (yes it's a small place but the advantage is I know my way around smile
it is best to let the system tell you you've made a mistake.  You work out
what went wrong, how to handle this condition, amend your code and retest
(but see my final comment!).

If you rely on an error handling routine to patch things up and keep things
going then you have hugely increased the complexity of your code.  If you
look at code you have to think in the back of you mind "well at this stage
the code looks like it has done this with global variable X but at certain
times the crash recovery routine may have changed the value under the feet
of this routine".  Hmmm.  I can see tricky bugs lurking.

And another thing: what happens if the error handling routine itself
generates an error!?

Finally: I know that everytime I travel by plane many many lines of code
are flying it (for some of the time at least).  I wonder if the language
they used has "error handling routines"?  Remember that the programmer(s)
are not on the plane with you.

Regards,

Andy Cranston.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu