Re: Exception misinformation
| From: | Hans Lellelid | Date: | Tue, 06 Jul 2004 23:50:55 +0000 |
| Subject: | Re: Exception misinformation | ||
| References: | 1 2 3 4 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-31683@lists.php.net to get a copy of this message | ||
Hi Justin,
Justin Patrin wrote:
Well, that would be a nice addition. There really should be a PHP5 manual out there in parallel with the PHP4 manual. Or at least all PHP5 functions should be in the manual as PHP5 only. Although an outside try/catch would be the same, right?Yes, outside try/catch would be the same. Depends on your application design. I tend to try [now] to write apps that have few entry points, using Front Controller-like patterns (like Mojavi, I guess). Makes it easy to ensure that all exceptions are handled. Other apps that have many entry point scripts would want to set a handler, probably, and also ensure that exceptions are caught by some middle/control-layer of the application. At least, that's how I'd do it.
Very nice, yes. -- What's wrong with looping forever? Gotta keep PHP in shape :) But yeah, your method would throw a nice informative exception in the end. It might be cool to create a CompositeException class that was designed to hold many exception objects and return all messages with getMessage() call, __toString(), etc. That'll be a useful PEAR_Exception subclass, I think, even though that scenario probably doesn't arise all that often. Hans$loaded = false; while(!$loaded) { try {Yes, I thought of this as well. Yours would loop forever if none that worked, though. Maybe something like this: $loaded = false; $strategy = true; $exceptionMessages = ''; while(!$loaded && $loadingStrategies) { try {$strategy = array_shift($loadingStrategies); $strategy->load($file); $loaded = true;} catch (Exception $e) {} }$strategy = array_shift($loadingStrategies); $strategy->load($file); $loaded = true;} catch (LoadingException $e) {$exceptionMessages .= $e.getMessage();} } if(!$loaded) { throw new LoadingException('No loading strategies worked. '.$exceptionMessages); }