Re: Using SPL Exceptions

From: Date: Fri, 22 Aug 2008 22:44:27 +0000
Subject: Re: Using SPL Exceptions
References: 1 2 3  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-50618@lists.php.net to get a copy of this message
Hello, On Fri, Aug 22, 2008 at 12:17 AM, Joe Stump <joe@joestump.net> wrote: > > On Aug 21, 2008, at 3:11 PM, Joshua Eichorn wrote: > >> Michael Gauthier wrote: >>> >>> What is PEAR's stance on using SPL exceptions in packages? Joe commented >>> on this in my recent Payment_PayPal_Soap proposal [1] and I've brought >>> it up on the list before [2]. >>> >>> [1] >>> http://pear.php.net/pepr/pepr-comments-show.php?id=556 >>> [2] >>> http://marc.info/?l=pear-dev&m=120576904018620&w=2 >>> >>> >>> >> We are currently working on a standard for this for pear2, but don't have >> any plans to update the standard for current pear code yet. >> In general the idea is too reuse the spl exceptions when possible but >> still make things catchable per package. >> You can use this by have an exception interface for the package, since you >> can catch based on an interface. >> The new standard is >> http://wiki.pear.php.net/index.php/PEAR2_Exception_Policy >> but its not done >> yet. > > As Josh says we're hammering it out. I feel pretty strongly that SPL > exceptions, for the most part, aren't meant to be caught. I can't see where you take that from. SPL Exceptions are simply a standard set of exceptions, that are used by SPL along with other extensions. > They're what I've > heard called "invariant exceptions". Mainly, if you call foo(int $id) with > foo('hello!') and you throw an InvalidArgumentException() there's not much > you *can* do to fix that. Same as any exception thrown anywhere, it stops the execution and goes to the catch, in which you decide what to do. I can't see why an invalid argument exception is worse than any other exception at "what you *can* do to fix it", if you even want to fix things. I.e. you could simply do : try { $foo = bar($invalid); } catch(InvalidArgumentException $e) { $foo = bar("default"); } ... > A generic error should be announced to the user > and it should be logged until you can add better input detection before > calling foo(). > > At any rate, we're working on it :) > > --Joe > > Regards -- Etienne Kneuss http://www.colder.ch Men never do evil so completely and cheerfully as when they do it from a religious conviction. -- Pascal

« previous php.pear.dev (#50618) next »