Article

From:
To:
Pete d'Oronzio
Subject:
Re: Exceptions vs Error codes
Newsgroup:
borland.public.delphi.objectpascal

Re: Exceptions vs Error codes

"Pete d'Oronzio" <✉pdmagic.com> wrote in message
news:3b76b1c3_1@dnews...
>....<snip>
> I'm not sure if this is a cut-and-dried question, or if I'm starting a
> religious war.  Either way, I'm very interested in the response.

Pete,

I'm not sure what you have already read, but back in June we had a big discussion on this issue under a thread which yours truly initiated under the title "Exceptions should be banned?". Rest assured that this theme does awaken lots of personal opinions related to programming style.
Exceptions are being used everywhere, in the VCL, in the RTL, in third-party components. Unless you write all of your own code (including your own framework) it is unlikely that your program will be entirely consistent in terms of exception raising behaviour.
From what I've seen in that discussion, the majority of Delphites believes strongly in an active usage of exceptions and relying on robust, state-free code combined with an intelligent top-level (default) exception handler. As you will also see from the referenced discussion, I am not among the Delphite majority in this respect.
I am not eager to have another major discussion on this point now, but FWIW let me summarize my current opinion on this issue:
I think it is inappropriate to raise exceptions for 'normal' error cases, or as a means of regular flow control; this, IMO, imposes too many constraints on the user of such code. I much prefer using error codes which enable me to decide how to react to an anomaly at the point where it happens (close to the source of error). In any case, exception-generating code (i.e. any code which uses Raise) should IMO be carefully documented as such. As for 'criticality' judgement on errors, there's the real catch (excuse the pun! <g>). How does a programmer (e.g. component writer) determine what is a 'critical'/unrecoverable error and what is not?
So: In the real world, be prepared for exceptions anywhere. One thing I've learnt from these discussions is that it's impossible to crusade against other programmers' preferences. So you've gotta be prepared for anything, anytime. Sucks, doesn't it. <g>
Kristofer
FYI: Phrase searches are enclosed in either single or double quotes
 
 
Originally created by
Tamarack Associates
Fri, 15 Nov 2024 04:51:53 UTC
Copyright © 2009-2024
HREF Tools Corp.