On 06/01/12 08:08, James Colannino wrote:
On 06/01/12 07:30, marco@xxxxxxxxxx wrote:
James Colannino<crankycyclops@xxxxxxxxx> hat am 1. Juni 2012 um 16:25
geschrieben:
Hey guys,
Haven't posted in a long time... Happy Memorial Day! I have an issue
with exception handling. I'm using a framework that throws a
"Database_Exception" object. I was expecting catch (Exception $var) to
be sufficient to catch this, but it doesn't. I have to do catch
(Database_Exception $var) to make it work. I've been reading that
Exception should be sufficient, since every exception object is a child
class of Exception. Did this perhaps change in 5.4? I think it was
working properly in 5.3, but I'm not sure.
Look at the definition of "Database_Exception" and see if it extends
Exception,
I'll guess it doesn't.
Nothing changed in PHP 5.4 to that.
Hey Marco,
Thanks for the reply! That was the first thing I checked.
class Database_Exception extends \FuelException {}
class Fuel_Exception extends \Exception {}
It's extending Exception, as expected. Also, can you throw classes
that don't extend Exception? It was always my understanding that
doing so would cause a fatal error.
I was right. From the documentation
(http://php.net/manual/en/language.exceptions.php):
"The thrown object must be an instance of the Exception
<http://www.php.net/manual/en/class.exception.php> class or a subclass
of Exception <http://www.php.net/manual/en/class.exception.php>. Trying
to throw an object that is not will result in a PHP Fatal Error."
James