Re: Exceptions: Error Codes Vs Class Names
| From: | Philippe Jausions | Date: | Sat, 28 Aug 2004 15:56:46 +0000 |
| Subject: | Re: Exceptions: Error Codes Vs Class Names | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-32998@lists.php.net to get a copy of this message | ||
Justin Patrin wrote:
On Fri, 27 Aug 2004 23:45:50 -0400, Davey <davey@php.net> wrote:When testing Justin remarks, also consider comparing catch() vs. switch(). For all fairness, the "catch()" and "case:" should be in the same order. It may not change the class vs. "exception code" topic, but it's interesting to see how they stand from the performance point of view. Also include uncaught exceptions in your test, to see how fast they comparatively bubble up. -PhilippeHey PEARs, Greg, The definition of a single class with 30 constants is about 4 times faster than of the 30 seperate classes, however: because with the single class we have to check the error code using: catch (errors $exception) {Ok, I can accept that the single class is faster. If we use that, how will re-throwing work? I suppose we can wrap the exception (as stated in the RFC), but this means: 1) 2 objects instead of 1 will be in that throw now. 2) Another object instatiation due to the above 3) another call to throw, due to the above 4) Possibly re-setting the code Whereas if you catch the specific error you want, it will bubble-up automatically.if ($exception->getCode() == exception_class::CONST) { echo $exception; }} as opposed to with the other method which means only the error we want to check for is caught: catch (error17 $exception) {echo $exception;}