Possible Duplicate:
Why catch and rethrow Exception in C#?
I sometimes come across C# code that looks like this:
try
{
// Some stuff
}
catch (Exception e)
{
throw e;
}
I understand its possible to do something like log the exception message and then rethrow it. I’m talking about a catch that only rethrows the exception. I don’t see a point to this. I have three questions:
1) Is there any advantage to this
2) Does this slow doen the code at all
3) Would it make any difference if the catch block were as follows:
catch (Exception)
{
throw;
}
This rethrows the exact same exception:
Whereas this rethrows the exception without the original stack trace:
There is often a good reason for
throw;as you can log the exception or do other things prior to rethrowing the exception. I am not aware of any good reasons forthrow e;as you will wipe out the valuable stack trace information.