[fpc-pascal] using exceptions

Marcos Douglas md at delfire.net
Mon Dec 19 21:23:00 CET 2011


On Mon, Dec 19, 2011 at 4:53 PM, ik <idokan at gmail.com> wrote:
> Hello,
>
> Exceptions like the name suggested, is to mark something that you are not
> suppose to expect.
> For example while getting a data something went wrong, like disconnection,
> wrong size of data etc...
>
> The usage of exception is very costly in performance, and there for should
> use only on specific events imho.
>
> 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 ?
>
> What do you think on this subject ? How would you choose when or where to
> use exceptions and why there ?

I use Exceptions to check the integrity of classes. I have one
Exception for each class (E<class_name>), most of the time.
I have Exceptions in 2 levels: user and Lib (API, business rules, etc).
If the Exception is in user level, the app do not aborts. But if the
Exception is in Lib level and the programmer did not catch, the app is
aborted.

I'm talkin bout Desktop apps. For Web applications the approach would
be different.

Marcos Douglas



More information about the fpc-pascal mailing list