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

Exception Handling

P: n/a
I would like to know if this is OK or if it is better to just let the
exception go instead of re-throwing it:

I have:

try
{
}
catch(OracleException ex)
{
// Do something
}
catch(Exception)
{
throw;
}

Should I only have:

try
{
}
catch(OracleException ex)
{
// Do something
}

And let the calling code handle any other type of exception.

Thank you for your input.

JFercan
May 11 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Fernando,

I don't see the point of the final throw for Exception, it basically is
the same as not having it there at all. Because of that, I wouldn't use it,
since it just complicates the code.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Fernando" <Fe******@discussions.microsoft.com> wrote in message
news:46**********************************@microsof t.com...
I would like to know if this is OK or if it is better to just let the
exception go instead of re-throwing it:

I have:

try
{
}
catch(OracleException ex)
{
// Do something
}
catch(Exception)
{
throw;
}

Should I only have:

try
{
}
catch(OracleException ex)
{
// Do something
}

And let the calling code handle any other type of exception.

Thank you for your input.

JFercan

May 11 '06 #2

P: n/a
Hi,

You should have it only if you plan to do something especial in that case.

If you are going to do nothing (as in your code) you do not need it.

Additionally you could use a finally clause that will execute always, you
could close connections, etc there
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Fernando" <Fe******@discussions.microsoft.com> wrote in message
news:46**********************************@microsof t.com...
I would like to know if this is OK or if it is better to just let the
exception go instead of re-throwing it:

I have:

try
{
}
catch(OracleException ex)
{
// Do something
}
catch(Exception)
{
throw;
}

Should I only have:

try
{
}
catch(OracleException ex)
{
// Do something
}

And let the calling code handle any other type of exception.

Thank you for your input.

JFercan

May 11 '06 #3

P: n/a
http://blogs.msdn.com/brada/

As per Brad Adams lecture I heard in Raleigh, NC at a user group meeting.
(Go Wolfpack!)

You should have many many , many more

try
{
}
finally
{
}
blocks in your code.. than

try
{}
catch(Exception ex)
{
//throw ex;
}
finally
{}

blocks.

Aka, always put in a finally, but leave the catching to the higher levels.

Most times, I have catching in my business layer, so I can bubble up a user
friendly message to the presentation layer.

While debugging, I'll put the catch in... to find out where the exact
exeptions is happening, but I comment it out for production/released code.

...

"Fernando" <Fe******@discussions.microsoft.com> wrote in message
news:46**********************************@microsof t.com...
I would like to know if this is OK or if it is better to just let the
exception go instead of re-throwing it:

I have:

try
{
}
catch(OracleException ex)
{
// Do something
}
catch(Exception)
{
throw;
}

Should I only have:

try
{
}
catch(OracleException ex)
{
// Do something
}

And let the calling code handle any other type of exception.

Thank you for your input.

JFercan

May 11 '06 #4

P: n/a
V
Hi Sloan,

this is interesting. i have never worked this way. normally our code
has a catch block most of the time. and the main reason is for logging
of the exception details.

How do you handle the logging of exceptions, then?

- Vaibhav
(interested in learning more and more)

May 11 '06 #5

P: n/a
On 11 May 2006 13:25:17 -0700, "V" <va*************@gmail.com> wrote:
Hi Sloan,

this is interesting. i have never worked this way. normally our code
has a catch block most of the time. and the main reason is for logging
of the exception details.

How do you handle the logging of exceptions, then?

- Vaibhav
(interested in learning more and more)


Good point, Vaibhav. I find that logging works best when done at the first
catch. Then you don't have to handle inner exceptions at the bubble up level.

Having said that, I see no problem with either method when not logging.

I too am interested in learning more...
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
May 12 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.