[fpc-pascal] using exceptions

noreply at z505.com noreply at z505.com
Thu Dec 22 01:23:08 CET 2011


> In our previous episode, ik said:
>> But we use exceptions even on places such as StrToInt, when the string
>> is
>> not an integer number, but we can expect to either have a number or
>> something else. So why use an exception there ?
>
> Because much used routines like strtoint are often used without proper
> checking. So strtoint throws exceptions, and people that want to handle
> errors properly use trystrtoint.

But why would they use trystrtoint when they could catch the exception
properly using an EXCEPT clause in the program?
Instead of checking for errors with trystrtoint, why not use exceptions
and then catch the exception? Well, for me I find exception code not to be
any clearer than TryStrToInt or Val()

>
>> What do you think on this subject ? How would you choose when or where
>> to
>> use exceptions and why there ?
>
> Roughly the same as you. Few exceptions, and usually when in to abort
> fairly
> deeply nested code.


There are exceptions all over lazarus and freepascal code, used as
errors.. the distinction between errors and exceptions is not clearly
defined, imo. They are used interchangbly.. even some of the exceptions
are called "ESomeError". So if they are errors, why are they exceptions?

Some people claim that exceptions are for extremely exceptional
circumstances and that errors are for all other cases.  However with Java
and Delphi it seems exceptions are actually errors, there is no
distinction. This needs to be academically researched more IMO.  The
Oberon developers have had intense discussions about it too, and yet
another word is used in oberon/component pascal... which is "TRAP".



More information about the fpc-pascal mailing list