Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-09

flag or exception?

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bisma Jayadi

Hi all...

I've always been confused about this subject... flag or exception for error handling? Can anyone share knowledges and ideas about when and where and why a (pascal) developer should chose one over another?

TIA.

-Bee-

has Bee.ography at:
http://beeography.wordpress.com

Reply by email

Micha Nelissen
to Bisma Jayadi
Bisma Jayadi wrote 5 lines
Hi all... I've always been confused about this subject... flag or exception for error handling? Can anyone share knowledges and ideas about when and where and why a (pascal) developer should chose one over another?

Depends on taste, and they have both advantages and disadvantages.

For example, it's easy to see when flag-using code is coded correctly (are the return values checked and handled?), while it's hard for exception-using code. Exceptions are usually slower as well. Exceptions are also not compatible to other languages, usually. OTOH, using exceptions is lazier/easier. If an error should never occur, then using exceptions will have more readable code, as not every function calling this must handle the possible error flag.

Micha

Reply by email

Michael Van Canneyt
to Bisma Jayadi: Hi all... I've always been confused about this subject... flag or exception for error…
Bisma Jayadi wrote 5 lines
Hi all... I've always been confused about this subject... flag or exception for error handling? Can anyone share knowledges and ideas about when and where and why a (pascal) developer should chose one over another?

This is highly developer dependent.

I personally prefer exception-based code.
I find it more clear and readable (less IF's), and more structured (easier cleanup in case of error, etc.)

But this is a personal opinion.

Michael.

Reply by email