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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Jan MontanoRank #1,295 · 1.3K reputationPosted Dec 6, 2007, 11:21 PM EST
kalyan Bandarupalli10 reputationPosted Jan 2, 2008, 8:11 PM EST
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.
Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Jan 18, 2008, 11:54 AM EST
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.