Re: type hinting throwing a fatal error

From: Date: Mon, 08 Aug 2005 12:50:46 +0000
Subject: Re: type hinting throwing a fatal error
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-17596@lists.php.net to get a copy of this message
Hi Toby, On Monday 08 August 2005 15:04, Tobias Schlitt wrote: > > The throw an Exception when SPL disabled and an InvalidArgumentException > > when it is enabled. > > That's senseless when writing applications that shall be version > independant. Just sticking to Exception should be fine. No it is not, in your application you can still simply catch Exception to be independent of SPL since the InvalidArgumentException class extends the Exception class. But by using nested Exceptions you can catch them independently. Else you would have to catch every Exception, parse the error message or trace to see wether it was a problem while calling the function/method or some code inside the function/method went wrong. <?php function foo() { $bar = ....; try { call_with_wrong_parameter($bar); } catch (InvalidArgumentException $e) { // bad function call... } } try { foo(); } catch (Exception $e) { // any other exception } ?> I'd like to see something like what Sebastian suggested. And imho it wouldn't really be a bc-break since an uncaught exception is fatal, too. johannes

« previous php.internals (#17596) next »