C# tips & tricks: Do you want to rethrow exception ?

Many times during development we really don’t want to handle exception every where, rather we like to throw it again. But what is the best way to do it:

catch(Exception ex)
{
throw;
}

OR

catch(Exception ex)
{
throw ex;
}

This article I found in net gives really good insight of it. It suggests to use first method, as it would not truncate previous stack trace information.

Advertisements

The URI to TrackBack this entry is: https://indiandeve.wordpress.com/2009/08/17/c-tips-tricks-do-you-want-to-rethrow-exception/trackback/

RSS feed for comments on this post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: