Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageOn 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
Post Follow-up to this messageThis 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 err ors 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 wrappe d in exceptions of some sort.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.