views:

77

answers:

1

I have a dead simple one-liner method that I don't want to see in the stack trace: is that possible? maybe mark it with an attribute?

Just to clarify, I'm not trying to print the trace, or rethrow, or have auto step-through in the debugger. I'd like the method to not show up in the trace in the first place, because the trace is then handled by some third-party code. I want control at runtime, I'm not interested about debugging. I'm saying this because most of what I've read on StackTrace seem to be about these topics.

+1  A: 

This can only be done when your method is inlined. Either the JIT does it, or you do it yourself (change the code). The JIT however, is pretty conservative about inlining methods and practically only does that when the method is very small, or when the method is used in a loop.

Steven
Hm... to be honest I doubt it: even if it's inlined wouldn't the StackTrace keep track somehow?And, it doesn't check out in practice since my method is there, both in debug and release, and it's only a one-line wrapper.
benblo
No. When a method is inlined, it is really gone. There is no method invocation therefore, a stack walk will not reveal it. Because a stack trace is built using a stack walk, the stack trace will not show your method anymore.
Steven