Re: Exceptions and Errors
| From: | Greg Beaver | Date: | Thu, 15 Apr 2004 01:09:00 +0000 |
| Subject: | Re: Exceptions and Errors | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-9160@lists.php.net to get a copy of this message | ||
Marcus Boerger wrote:
Hello Jani, Wednesday, April 14, 2004, 3:35:23 AM, you wrote:don't forget 3) Use a factory method and an empty constructor $db = new SQLiteDatabase::factory(); if (!$db) {On Wed, 14 Apr 2004, Marcus Boerger wrote:This is actually a pretty nasty side effect of throwing exceptions in ctors because these two lines have *very* different results if they fail:$db = new SQLiteDatabase(); $db = sqlite_open();The first is fatal; the second isn't.So to use the OO API of sqlite requires that I use exceptions with it too..? It's pretty unfriendly to force the use of exceptions like this, IMO.As i explained there is no good other way to tell the user thector has failed. The two ways out out are: 1) Using empty ctors and check whetehr the instance is initialized on every method call which is slower and different from our other objects. 2) Pass another parameter by reference '&$failed' which will hold the state of the ctor execution. Still you need to solve the now illegal instance which pretty much leads to 1.
// handle error} Greg