473,398 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Responding to Exceptions

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
2 1138
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: David Turner | last post by:
Hi all I noticed something interesting while testing some RAII concepts ported from C++ in Python. I haven't managed to find any information about it on the web, hence this post. The problem...
21
by: dkcpub | last post by:
I'm very new to Python, but I couldn't find anything in the docs or faq about this. And I fished around in the IDLE menus but didn't see anything. Is there a tool that can determine all the...
26
by: OvErboRed | last post by:
I just read a whole bunch of threads on microsoft.public.dotnet.* regarding checked exceptions (the longest-running of which seems to be <cJQQ9.4419 $j94.834878@news02.tsnz.net>. My personal...
9
by: Gianni Mariani | last post by:
I'm involved in a new project and a new member on the team has voiced a strong opinion that we should utilize exceptions. The other members on the team indicate that they have either been burned...
8
by: Shamrokk | last post by:
My application has a loop that needs to run every 2 seconds or so. To acomplish this I used... "Thread.Sleep(2000);" When I run the program it runs fine. Once I press the button that starts the...
6
by: RepStat | last post by:
I've read that it is best not to use exceptions willy-nilly for stupid purposes as they can be a major performance hit if they are thrown. But is it a performance hit to use a try..catch..finally...
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
2
by: Zytan | last post by:
I know that WebRequest.GetResponse can throw WebException from internet tutorials. However in the MSDN docs: http://msdn2.microsoft.com/en-us/library/system.net.webrequest.getresponse.aspx It...
0
RedSon
by: RedSon | last post by:
Chapter 3: What are the most common Exceptions and what do they mean? As we saw in the last chapter, there isn't only the standard Exception, but you also get special exceptions like...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.