Re: PEAR's Error Handling and PHP5
| From: | Hans L | Date: | Wed, 07 Jun 2006 18:00:49 +0000 |
| Subject: | Re: PEAR's Error Handling and PHP5 | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-42835@lists.php.net to get a copy of this message | ||
Hi -
>> Con Exceptions:
>> * Will cause multiple error handling paradigms to be used at once as
>> likely PHP4 and PHP5 package will be used side-by-side for a time
>
> People who want a pure PHP5 E_STRICT-compliant applications will not use
> PHP4 packages side-by-side with PHP5. In fact, I've heard from quite a
> few developers targeting PHP5 that they're trying to avoid PEAR packages
> these days either because they can't be sure if they'll still run when
> the next PHP upgrade comes or because they simply don't fit into their
> error handling scheme.
Personally, I "port" the PEAR packages I use to PHP5 -- doing things
like find/replace on return PEAR::raiseError() ... to throw new
PEAR_Exception( and removing any if(PEAR::isError($res)) code. The end
result is code that is smaller, easier to read, and less likely to have
unhandled errors. But in general, this is true; I write PHP5-only apps,
and so all my error handling is PHP5 (i.e. Exception).
>> * They don't allow PEAR_Error's tricks such as changing error handling
>> (dying, callback, etc), and expecting errors
>
> Some of this stuff should not be hard to implement when all Exceptions
> extend a base PEAR_Exception class and possibly add a function that
> handles uncaught exceptions via set_exception_handler().
I haven't yet encountered any case where I felt that PEAR_Exception was
insufficient. I have all my exceptions logged while debugging (and
adding a listener is great for that), but at some level I know I have to
catch them & handle them.
> I have yet to see someone bring up a valid reason not to use exceptions.
> IMHO, the advantages by far outweigh the tiny little disadvantages one
> might see.
Obviously, I heartily agree. I'm more than willing to spend an hour
grepping through PEAR classes to change the error handling, because it
will save me much more time down the road -- and because I can rest
easier knowing that my application is handling all my errors in a
consistent fashion. There's really no choice in my mind :)
That's my .02 on the matter, anyway.
Cheers,
Hans