I have the following PHP code:
foreach (...) {
try {
$Object = MyDataMapper::getById(123);
if (!$Object->propertyIsTrue()) {
continue;
}
}
catch (Exception $e) {
continue;
}
}
MyDataMapper::getById() will throw an Exception if a database record is not found. Here is the definition of that method:
public static function getById($id) {
$query = "SELECT * FROM table WHERE id = $id";
$Connection = Database::getInstance();
$Statement = $Connection->prepare($query);
$Statement->execute();
if ($Statement->rowCount() == 0) {
throw new Exception("Record does not exist!");
return null;
}
$row = $Statement->fetch();
return self::create($row);
}
When this code is called for a database record id that does not exist, I get a fatal uncaught exception 'Exception' error.
Why is this? Clearly I am catching the exception... What am I doing wrong?
I am sure an exception is being thrown. Is there something wrong with how I am handling the exception--maybe with the continue?
EDIT
Thanks to help from jitter, the following workaround solves this problem:
if (!$Object->propertyIsTrue()) {
// Workaround to eAccelerator bug 291 (http://eaccelerator.net/ticket/291).
$foo = 555;
continue;
}