At 01:00 PM 2/3/2007, Cosmin Prund wrote:
>The statement "And I do so without setting up unnecessary exception
>handling which is, I expect, much more expensive than several IS tests"
>makes it look like exception handling is something expensive and it
>should be avoided. It's not, and it should be used as often as possible.

Yes, exception handling should be encouraged. However, sometimes developers 
use exceptions to trap and process conditions that are expected to occur in 
the normal course of operations and this should be avoided. So, you need to 
be judicious.

For example, when translating a user-entered string into a numeric value. 
In those cases the developer can reasonably expect the user to enter a 
non-numeric at some point.  You might be tempted, therefore, to trap the 
translation error with an exception and process the "error" that way.

However, there have been considerable argument about whether this is 
correct and proper use of the exception mechanism. Some would argue that 
exception handling code should ONLY be used for conditions that cannot be 
anticipated in the normal course of operations. The above example would NOT 
qualify in this regard.

Others would argue that exception handling should be used everywhere it 
works, without regard for the frequency of the exception occurrences. They 
think that even if a condition can normally occur 50% of the time it is OK 
to use the exception mechanism to perform what is essentially an if-test in 
the logic of the program.

I agree with the former position and abhor the use of exception handling to 
control normal logic flow in the program.

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to