Rethrowing exceptions

1 view
Skip to first unread message

Dennis Dunn

unread,
Apr 7, 2011, 2:56:03 PM4/7/11
to Columbus Downtown Developer Book Club
I hate saying "I don't know" so when I got back to the office I did
some research on the different ways to rethrow an exception and this
is what I found out....

MSIL has two different instructions for throwing an exception –
“throw” and “rethrow.”

The statement “throw ex;” gets compiled into a call to the “throw” IL
instruction.

The statement “throw;” gets compiled into a call to the “rethrow” IL
instruction.

The “throw” IL instruction sets the stack trace of the Exception
object to the current stack frame which is why you lose your stack
trace when you use the “throw ex;” form.

Later,
--dennis

Jeffrey Miller

unread,
May 4, 2011, 1:26:55 PM5/4/11
to Columbus Downtown Developer Book Club
Thanks for the research Dennis. I'm putting that in my bag-O-tricks/
bag-O-gotchas.
Reply all
Reply to author
Forward
0 new messages