473,405 Members | 2,141 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,405 software developers and data experts.

Is there anyway to catch both exceptions in the following example?

http://www.skidmore.edu/~h_blackw/finally.gif
I can only catch the exception thrown in the finally code section.
even if I do
catch(InvalidOperationException)
Nov 15 '05 #1
4 2578
try
{
throw new ApplicationException("Exception1");
}
catch
{
throw new ApplicationException("Exception in try block.");
}
finally
{
throw new ApplicationException("Exception in finally.");
}

Exception thrown in try block. Exception caught in catch block. Catch
block throws new exception, however finally also wants to throw an
exception. dont think you want to throw another exception in finally.

--
William Stacey, DNS MVP

"Hasani" <HJ****@hotmail.c0m> wrote in message
news:9_******************@twister.nyc.rr.com...
http://www.skidmore.edu/~h_blackw/finally.gif
I can only catch the exception thrown in the finally code section.
even if I do
catch(InvalidOperationException)

Nov 15 '05 #2
Hasani,

Yes, that is right, because the exception thrown in the finally section
is the one that takes precedence (it is the most recent one thrown).

What are you trying to do?
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Hasani" <HJ****@hotmail.c0m> wrote in message
news:9_******************@twister.nyc.rr.com...
http://www.skidmore.edu/~h_blackw/finally.gif
I can only catch the exception thrown in the finally code section.
even if I do
catch(InvalidOperationException)

Nov 15 '05 #3
100
Hi Hasani,
Throwing exception from within finally block is really bad idea and should
be avoided. Actually, throwing exception from finally block masks the first
exception and may confuse your exception handling logic. If you have code
that might throw exception in finally block use designated try/catch block
for it and recover in the finally block.

B\rgds
100

"Hasani" <HJ****@hotmail.c0m> wrote in message
news:9_******************@twister.nyc.rr.com...
http://www.skidmore.edu/~h_blackw/finally.gif
I can only catch the exception thrown in the finally code section.
even if I do
catch(InvalidOperationException)

Nov 15 '05 #4
"What are you trying to do?"

The real question is, what am I going to do, and I could only determine this
from the answers to my question. Thx you for your answers.

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:Oh**************@TK2MSFTNGP11.phx.gbl...
Hasani,

Yes, that is right, because the exception thrown in the finally section is the one that takes precedence (it is the most recent one thrown).

What are you trying to do?
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Hasani" <HJ****@hotmail.c0m> wrote in message
news:9_******************@twister.nyc.rr.com...
http://www.skidmore.edu/~h_blackw/finally.gif
I can only catch the exception thrown in the finally code section.
even if I do
catch(InvalidOperationException)


Nov 15 '05 #5

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

Similar topics

10
by: Gary.Hu | last post by:
I was trying to catch the Arithmetic exception, unsuccessfully. try{ int a = 0, b = 9; b = b / a; }catch(...){ cout << "arithmetic exception was catched!" << endl; } After ran the program,...
9
by: Steven Blair | last post by:
Hi, I need to catch exceotions on File.Delete() After checking the help, I have noticed that thgere are serevral Exceptions that can be thrown. My question is, should I catch all thes...
3
by: Steve | last post by:
I have some general catch clauses in my app as follows: try { } catch(Exception ex) { } try
7
by: Arjen | last post by:
Hi, I'm doing this: try { try { } catch(Exception ex){ throw;
6
by: Martin Ortiz | last post by:
Which is best approach? Should Try + Catch be used to only deal with "catastrophic" events (like divide by zero, non-existant file, etc...etc...) Or should Try + Catch be used IN PLACE of...
32
by: cj | last post by:
Another wish of mine. I wish there was a way in the Try Catch structure to say if there wasn't an error to do something. Like an else statement. Try Catch Else Finally. Also because I...
3
by: Martijn Mulder | last post by:
Is it good style to use a try...catch clause in the constructor or is it something that is frowned upon?
6
by: rhaazy | last post by:
I am looking for some feedback on using try catch statements. Usually when I start a project I use them for everything, but stop using them as often after the "meat n' potatos" of the project is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.