Wednesday, January 09, 2008

Throw Exception

You might have figured out ‘Find 10 difference’ column in from your favorite news paper. Here comes it again with finding one difference that affects your code:

try
{
}

catch (Exception)
{

throw;
}

and

try
{
}

catch (Exception ex)
{
throw ex;
}

Answer: In case of ‘rethrowing’ exception, 1st case would still save the stack trace. Re-throwing the same exception in 2nd case will result into losing your stack trace.

No comments: