By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,304 Members | 1,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,304 IT Pros & Developers. It's quick & easy.

Responding to Exceptions

P: n/a
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.

Feb 24 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
e_*******@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.
js*******@attglobal.net
==================
Feb 25 '07 #2

P: n/a
On Feb 24, 6:03 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
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.

Feb 25 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.