It depends! Let me explain…
Here is the output when executing it in DEBUG:
As you can see, we get the full trace that starts with Main(), A(), B(), C() and finally BadMethod().
Now, lets try to execute it in RELEASE:
Now you can see that the outcome changed. The trace is shorter and we only see Main() and BadMethod().
What Is The Reason?
DEBUG and RELEASE build configurations are different in a way that RELEASE are optimized for performance. Most of the performance optimizations are done by the JIT compiler. So, back to the outcome, we can see the the JIT had optimized our code for better performance. In fact not every method got their own local stack frame as they were optimized into fewer methods.
It is possible to force the JIT not to inline the code, or in other words, not to optimize the code for us. You can do that in several ways:
- Use Try & Catch on every method.
- Turn off JIT optimizations.
If you try each of the above you will get the same outcome for both DEBUG and RELEASE. Having said that, my personal opinion on the matter is that we should try to let the JIT do its work and what it does best…Optimization!