Re: PHP5: Exceptions must valid objects that are derived from class Exception?

From: Date: Sun, 22 Feb 2004 14:56:08 +0000
Subject: Re: PHP5: Exceptions must valid objects that are derived from class Exception?
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-8047@lists.php.net to get a copy of this message
On Sun, Feb 22, 2004 at 03:36:49PM +0100, Erik Franzén wrote : > I am prototyping on a PHP5 application using PEAR and I ran into a > strange error. > > if (PEAR::isError($mReturn)) { > throw $mReturn; > } > > PEAR is not configured to return exceptions instead of PEAR Errors and > the above code will generate the following error if $mReturn is a PEAR > Error. > > PHP Fatal error: Exceptions must valid objects that are derived from > class Exception in E:\PHPSource\PHPFTP\Source\include\\db.inc.php on > line 226 > > Why must I use the built in exception class? The explantion in release > notes for PHPb4 is that it allows a general catch(Exception $e) > statement to catch all exceptions. > > Isn't that up to the developer to deal with it? The catch-all helps catching any type of exception, _given that_ it is derived from class Exception. The motivation behind it, and this makes sense to me, I'm pro this behaviour, is, that this way the interface of the Exception class is well defined. You can always count that you have the methods getMessage, getCode, getFile, getTraceAsString, etc. Which is IMO good. - Markus

« previous php.internals (#8047) next »