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 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php