Re: Exception misinformation

From: Date: Tue, 06 Jul 2004 23:54:57 +0000
Subject: Re: Exception misinformation
References: 1 2 3 4 5  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-31688@lists.php.net to get a copy of this message
On Tue, 06 Jul 2004 19:50:55 -0400, Hans Lellelid <hans@velum.net> wrote: > 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. > > >> > >>$loaded = false; > >>while(!$loaded) { > >> try { > >> $strategy = array_shift($loadingStrategies); > >> $strategy->load($file); > >> $loaded = true; > >> } catch (Exception $e) {} > >>} > > > > > > > > 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 (LoadingException $e) { > > $exceptionMessages .= $e.getMessage(); > > } > > } > > > > if(!$loaded) { > > throw new LoadingException('No loading strategies worked. > > '.$exceptionMessages); > > } > > > > 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. > Or PEAR_Exception could be altered to allow an array of exceptions as well. Either would work. Having an explicit CompositeException would keep some extra code out of PEAR_Exception, but it would also mean more code (files) to include if you needed the funcitonality. (BTW, I did want to have a composite, I just saw that PEAR_Exception didn't allow it, so I kludged that error message). -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin--

« previous php.pear.dev (#31688) next »