Home > Archive > PHP Language > July 2006 > PHP5 and exception handling
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
PHP5 and exception handling
|
|
| Guillaume Métayer 2004-08-04, 3:55 am |
| Hello,
I'm used to exception handling in C++ or Delphi/Object Pascal and I had
lotsa expectations for PHP5 exception handling, especially since I started
working on a project with MSSQL, and I need transaction support: do a few
inserts and rollback the whole thing if an error occured.
I might be wrong, but I searched a lot and read a lot and ran some tests,
and exceptions handling in PHP5 sucks. They implemented exceptions in
objects, but the core language itself doesnt throw expections. For example,
a division by zero in Object Pascal will throw exception EDivisionZero or
something, and most functions/objects will also throw exceptions. It's safe
then to write a try .. catch block because you know you're gonna catch
everything.
In PHP5 it seems you have to code and check everything yourself to make sure
everything throws an exception, but that defeats the whole purpose of
feeling save about catching any exception.
Am I completely wrong and total idiot because I don't have a clue or am I
right? Is there something I'm not getting?
How would you implement some clean way to handle transactions with PHP?
-------
Guillaume
Montreal, Canada
| |
| eclipsboi 2004-08-04, 3:55 am |
| On Wed, 4 Aug 2004 00:21:32 -0400, "Guillaume Métayer"
<guillaumeNOmetayerSPAM@hotmail.com> wrote:
>... They implemented exceptions in
>objects, but the core language itself doesnt throw expections.
Yes, because the focus on PHP5 was a more OO oriented class
structure--that pretty much is exclusive to classes and not PHP as a
whole. For more information on the significant changes in PHP5, to
avoid further confusion, try reading at least one more site (if you
haven't already):
http://www.zend.com/php5/articles/e...hp5-changes.php
| |
| ybakos 2006-07-04, 11:10 am |
| This response is a little dated from your original post, but the answer is 'Yes, that is right.'
Exception handling in PHP5 works fine, but you can't "catch" the typical errors raised by PHP's built-in functions. So you can implement the throwing of exceptions in your own classes and other libraries, but that's about it.
Too bad there wasn't an easy way for the PHP crew to implement errors wrapped in exceptions of some sort. |
|
|
|
|