Throw VS rethrow : same result?

前端 未结 5 1706
隐瞒了意图╮
隐瞒了意图╮ 2021-02-20 11:26

refering to a lot of documentation on the net, particularly on SO, eg : What is the proper way to re-throw an exception in C#? there should be a difference between \"throw e;\"

5条回答
  •  隐瞒了意图╮
    2021-02-20 11:55

    I have tried running this code myself and the debug build works as I expected but I got the same result as you in the release build.

    I suspect what's happening is that the compiler inlining has simply replaced the BadGuy() call with throw new Exception(); because that's the only statement in BadGuy().

    If you switch off the 'Optimize code' option in the project properties -> Build screen, then both Release and Debug build produces the same result which shows BadGuy() at the top of the stack trace.

提交回复
热议问题