Re: Using SPL Exceptions

From: Date: Thu, 21 Aug 2008 22:17:35 +0000
Subject: Re: Using SPL Exceptions
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-50611@lists.php.net to get a copy of this message
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. 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. 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

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