Please answer this simple SPAM challenge: two minus zero?
(Example: nine)

The Note You're Voting On

hartym dot dont dot like dot spam at gmail dot com
10 years ago
@serenity: of course you need to throw exception within the try block, catch will not watch fatal errors, nor less important errors but only exceptions that are instanceof the exception type you're giving. Of course by within the try block, i mean within every functions call happening in try block.

For example, to nicely handle old mysql errors, you can do something like this:

$connection = mysql_connect(...);
  if (
$connection === false)
    throw new
Exception('Cannot connect do mysql');

/* ... do whatever you need with database, that may mail and throw exceptions too ... */

catch (
Exception $e)
/* ... add logging stuff there if you need ... */

echo "This page cannot be displayed";


By doing so, you're aiming at the don't repeat yourself (D.R.Y) concept, by managing error handling at only one place for the whole.

<< Back to user notes page

To Top