[nycphp-talk] If/else vs Try/catch
John Zabroski
johnzabroski at yahoo.com
Wed Nov 28 15:56:39 EST 2007
--- csnyder <chsnyder at gmail.com> wrote:
>
> Error handling doesn't need to be part of your
> program logic anymore.
>
> --
> Chris Snyder
> http://chxo.com/
Be careful saying that, especially to a newbie. While
experienced programmers presumably understand
statements other experienced programmers like you
make, a newbie might not understand an overly general
statement like the one you just made. I understand
what you are saying, but it is a gross simplification
for someone needing deep, penetrating understanding of
a new concept.
Error handling does not just magically disappear from
program logic, even if you use try/catch. In fact, it
is quite easy for code to fall prey to a Split Cleaner
bug pattern when using exception handling. Ken Downs
posted a "gotcha" with exception handling already.
Try/catch does not eliminate error handling from
program logic. Instead, it does only what it was
originally designed to do: let the caller of the
function determine how to respond to a failure
condition. Explicitly, the caller has greater
responsibility in the call chain, because the calling
function has more contextual knowledge and should be
more able to recover from failure gracefully.
____________________________________________________________________________________
Be a better sports nut! Let your teams follow you
with Yahoo Mobile. Try it now. http://mobile.yahoo.com/sports;_ylt=At9_qDKvtAbMuh1G1SQtBI7ntAcJ
More information about the talk
mailing list