Article

From:
To:
All
Subject:
Exceptions vs Error codes
Newsgroup:
borland.public.delphi.objectpascal

Exceptions vs Error codes

Hi all,

I've only recently begun using exceptions in my code. I certainly see their power, and I could see entirely doing away with error codes. However, in reading some of the posts in various groups, it seems that some people feel that exceptions are for situations that are not generally recoverable.
The way I hear the description is like this: The reason for throwing an exception is because something critical has failed and not much can be done except for stopping the current operation and returning to some level of the message loop. (i.e. File to be opened didn't exist, must bail on operation) This seems too limited, and not taking full advantage of the exception mechanism.
When I look at the level of detail available using exceptions, it seems that there is a lot of leeway for trapping specific errors and handling them. (i.e. try to open a port, operation throws an exeption indicating that the port is unavailable, catch it and try opening another port instead)
It might even seem to make sense to use exceptions in cases where the exception is expected. (i.e. repeat reading lines from a file, continue processing until exception is thrown indicating end-of-file)
I'm interest in how others use exceptions with reference to these examples.
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.
Thanks,
-pete
FYI: Phrase searches are enclosed in either single or double quotes
 
 
Originally created by
Tamarack Associates
Fri, 29 Mar 2024 06:24:31 UTC
Copyright © 2009-2024
HREF Tools Corp.