hello sir/madam,
could you please tell me what happens in the following session1 and session2?
Section 1
Some code
}
Catch(exception e)
{
Throw e;
}
Try{
Some code
}
Catch(exception e)
{
Throw;
}
hello sir/madam,
could you please tell me what happens in the following session1 and session2?
Section 1
Some code
}
Catch(exception e)
{
Throw e;
}
Try{
Some code
}
Catch(exception e)
{
Throw;
}
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Niradhip ChakrabortyPosted Jan 18, 2008, 4:54 PM
throw e will restart the stack trace where as 'throw' retains the original stack trace.
Basically MSIL (CIL) has two instructions - "throw" and "rethrow" and guess what - C#'s "throw ex;" gets compiled into MSIL's "throw" and C#'s "throw;" - into MSIL "rethrow"! Basically I can see the reason why "throw ex" overrides the stack trace, that's quite intuitive if you think about it for a moment. But "throw" syntax for "rethrow" instruction is not really intuitive. It smells stack based MSIL, which is obviously under the cover, but actually should be kept there. I guess they wanted to keep number of C# keywords small, that's the reason. So you just better know this stuff - use "throw;" to re-throw an exception in .NET.
kalyan BandarupalliPosted Jan 3, 2008, 1:11 AM
Hi
Both are having the saming functionality. the difference comes in memory. extra stack inf'n will build when i say throw ex and extra lines will be added to the MSIL where as it is not in the throw statement.
Jan MontanoPosted Dec 7, 2007, 4:21 AM