Rethrowing exceptions, the right way
I have read the Exception Handling Best Practices article in .NET in CodeProject and all this time I thought that rethrowing exceptions is this way:
[code language="C#"]
try
{
// Some code that throws an exception
}
catch (Exception ex)
{
// some code that handles the exception
throw ex;
}
[/code]
I just learned that it should have been this way:
[code language="C#"]
try
{
// Some code that throws an exception
}
catch (Exception ex)
{
// some code that handles the exception
throw;
}
[/code]
Reason: Stack Trace Preservation
Currently, I still don’t have a solid understanding on .NET Exceptions, its internals, etc. I still have to do a number of readings about them…