[fpc-pascal] using exceptions

noreply at z505.com noreply at z505.com
Thu Dec 22 01:29:09 CET 2011


Marcos wrote:
> I use Exceptions to check the integrity of classes. I have one
> Exception for each class (E<class_name>), most of the time.


Another problem with errors is that sometimes it is hard for a class to
return errors. In procedural programming you can usually return an error
as a parameter but sometimes in class programming it is difficult for
classes to just return errors.

Exceptions are an attempt to solve the problem, but imo this still doesn't
solve all problems and our applications are full of wild exceptions going
off despite our attempts to solve the problem.. because people fail to
check exceptions and catch them. usually I see code like this:

Try

Finally


You don't see as much Try Except, it's more Try Finally. People ignore the
exceptions because it's an accepted thing to do. Then the end user of the
application gets a strange exception message instead of a user friendly
one. For example, if a file is not found, I like to give a polite "Cannot
find file" message.. but usually in delphi apps and examples all over the
newsgroups you see just an EFileNotFound exception pop up instead. Or,
with StrToInt, a similar obscure exception message to the end user instead
of a more friendly one.



More information about the fpc-pascal mailing list