473,506 Members | 9,749 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Good practice for exception handling

When implementing exception handling which one of these two alternative
ways of exception-handling is the better one?

************************************************** ****
Alt1)
************************************************** ****
try
{
codeline1; //throws exception1, exception2 and exception3
codeline2; //throws exception4, exception5 and exception6
codeline3; //throws exception7, exception8 and exception9
codeline4; //throws exception10, exception11 and exception12
codeline5; //throws exception13, exception14 and exception15
}

catch(exception1){}
catch(exception2){}
catch(exception3){}
...............................
catch(exception14){}
catch(exception15){}
************************************************** ****
OR Alt 2)
************************************************** ****
try
{
codeline1; //throws exception1, exception2 and exception3
}
catch(exception1){}
catch(exception2){}
catch(exception3){}

try
{
codeline2; //throws exception4, exception5 and exception6
}
catch(exception4){}
catch(exception5){}
catch(exception6){}

try
{
codeline3; //throws exception7, exception8 and exception9
}
catch(exception4){}
catch(exception5){}
catch(exception6){}
************************************************** ****
Feb 26 '06 #1
2 2917
What's the idea for Alt 2 case?
When implementing exception handling which one of these two alternative
ways of exception-handling is the better one?

************************************************** ****
Alt1)
************************************************** ****
try
{
codeline1; //throws exception1, exception2 and exception3
codeline2; //throws exception4, exception5 and exception6
codeline3; //throws exception7, exception8 and exception9
codeline4; //throws exception10, exception11 and exception12
codeline5; //throws exception13, exception14 and exception15
}

catch(exception1){}
catch(exception2){}
catch(exception3){}
...............................
catch(exception14){}
catch(exception15){}
************************************************** ****
OR Alt 2)
************************************************** ****
try
{
codeline1; //throws exception1, exception2 and exception3
}
catch(exception1){}
catch(exception2){}
catch(exception3){}

try
{
codeline2; //throws exception4, exception5 and exception6
}
catch(exception4){}
catch(exception5){}
catch(exception6){}

try
{
codeline3; //throws exception7, exception8 and exception9
}
catch(exception4){}
catch(exception5){}
catch(exception6){}
************************************************** ****


--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche

Feb 26 '06 #2
The real question is what are the requirements of the code? Does each
codeline need to be capable of recovering independently from the others or
do they share recovery paths? Is there even a recovery path? What are the
requirements for calling code; does it allow exceptions to bubble up or is
it defined as completely handling all exceptions within the code body? In
other words, the answer to your question is: it depends.

"John Smith" <so*****@microsoft.com> wrote in message
news:OC**************@TK2MSFTNGP15.phx.gbl...
When implementing exception handling which one of these two alternative
ways of exception-handling is the better one?

************************************************** ****
Alt1)
************************************************** ****
try
{
codeline1; //throws exception1, exception2 and exception3
codeline2; //throws exception4, exception5 and exception6
codeline3; //throws exception7, exception8 and exception9
codeline4; //throws exception10, exception11 and exception12
codeline5; //throws exception13, exception14 and exception15
}

catch(exception1){}
catch(exception2){}
catch(exception3){}
..............................
catch(exception14){}
catch(exception15){}
************************************************** ****
OR Alt 2)
************************************************** ****
try
{
codeline1; //throws exception1, exception2 and exception3
}
catch(exception1){}
catch(exception2){}
catch(exception3){}

try
{
codeline2; //throws exception4, exception5 and exception6
}
catch(exception4){}
catch(exception5){}
catch(exception6){}

try
{
codeline3; //throws exception7, exception8 and exception9
}
catch(exception4){}
catch(exception5){}
catch(exception6){}
************************************************** ****

Feb 26 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2350
by: Sai Kit Tong | last post by:
I posted for help on legacy code interface 2 days ago. Probably I didn't make it clear in my original mail. I got a couple of answers but none of them address my issues directly (See attached...
4
7600
by: James Radke | last post by:
Hello, I am looking for guidance on best practices to incorporate effective and complete error handling in an application written in VB.NET. If I have the following function in a class module...
1
1864
by: GS | last post by:
Any points of what would be the good error handling design for application? User error handling in Application_OnError and throw() new errors on conditions through the code? I'd like utlimiately to...
6
2084
by: RonL | last post by:
What is the recommended best technique for handling errors/exceptions in ASP.Net. I've read about the following techniques: 1. Try/Catch 2. Page_Error 3. Application_Error in the...
5
1717
by: csgraham74 | last post by:
Hi guys, Basically i have been developing in dotnet for a couple of years but ive had a few issues in regards to error handling. For example - I have a class that i call passing in a stored...
5
1689
by: mike3 | last post by:
Hi. Is this a good idea?: <begin code> /* Addition operator: += */ const BigFix &BigFix::operator+=(const BigFix &rhs) { ErrorType err; int lhs_sign = sign, rhs_sign = rhs.sign;
206
8170
by: WaterWalk | last post by:
I've just read an article "Building Robust System" by Gerald Jay Sussman. The article is here: http://swiss.csail.mit.edu/classes/symbolic/spring07/readings/robust-systems.pdf In it there is a...
3
1643
by: roger.dunham | last post by:
Hi there, I am writing an application that performs calculations on records within a data table. There may be many records in a data table. There are situations where the calculation may not...
5
2459
by: =?Utf-8?B?QmlsbHk=?= | last post by:
asp.net 2.0 vs2005 What is best practice for exception handling on a website in vs2005? I was going to catch errors in application on_error event, log them to the event log, then send users to...
0
7308
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
7371
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...
1
7023
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
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.