Hi!

Because checking that the returned variable is `!== FALSE` is *way*
better than throwing an exception, right?

Yes, it is. You can control it, unlike the exception which you can not,
unless, again, you wrap everything into try/catch on every kind of
exception possible.

Have you stopped for a moment to think this opinion through? Look at two typical patterns of error handling. The examples below are generalized from my file cache code. Having no cache is exceptional, because 99.999% of the time I run this, there is cache, except the first time when there's not.

Tell me again how you using try..catch is very verbose and how you need to supply multiple catch blocks for "every kind of exception possible"?

With exceptions:
----------------
try {
   fileop1();
   fileop2();
   fileop3();
   normal_actions();
} catch (IOException $e) {
   exceptional_actions();
}

Without exceptions:
--------------------
$valid = true;
if (fileop1() !== FALSE) {
   $valid = false;
}

if ($valid && fileop2() !== FALSE) {
   $valid = false;
}

if ($valid  && fileop3() !== FALSE) {
   $valid = false;
}

if ($valid) {
   normal_actions();
} else {
   exceptional_actions();
}

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to