|
Posted by e_matthes on 02/25/07 05:59
On Feb 24, 6:03 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> e_matt...@hotmail.com wrote:
> > Hello everyone,
>
> > I have set up some custom exceptions, and have managed to implement
> > the proper responses to those exceptions. I have something like this:
>
> > try {
> > do something;
> > } catch (ExceptionA $e) {
> > response;
> > } catch (ExceptionB $e) {
> > response;
> > } catch (ExceptionC $e) {
> > response;
> > } catch (ExceptionD $e) {
> > response;
> > } catch (Exception $e) {
> > respond to unknown exception;
> > }
>
> > It's a little clunky though, because sometimes responses to Exceptions
> > B, C, and D are the same. Is there any way to collect those specific
> > exceptions together in a specific response situation? In other words,
> > what I'd love to do is:
>
> > try {
> > do something;
> > } catch (ExceptionA $e) {
> > response;
> > } catch (ExceptionB $e OR ExceptionC $e OR ExceptionD $e) {
> > response;
> > } catch (Exception $e) {
> > respond to unknown exception;
> > }
>
> > I know I could catch Exception A, then catch the parent Exception
> > class, then $e->getcode, and respond to the code in an if-else clause
> > or switch clause. But is there any way to do this with the exceptions
> > themselves, i.e. catch a group of exceptions together? Thanks.
>
> No, but you can derive B, C and D from the same class (BCD) and handle
> an exception for BCD.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================
Thank you! That helps.
[Back to original message]
|