In C# (or .NET in general) can you mask the call stack level where an exception was thrown via attributes?

对着背影说爱祢 提交于 2019-12-05 12:22:28

Please see the Just My Code option. You need to decorate DoWorkHelper with DebuggerHiddenAttribute or DebuggerNonUserCodeAttribute.

Just adding what I've found to better explain so people don't have to go looking elsewhere...

There are three attributes related to this: DebuggerHidden, DebuggerStepThrough, and DebuggerNonUserCode.

Here are the rules:

When Just My Code is not checked:

  • DebuggerNonUserCode
    This is basically ignored. Breakpoints, step-into and exceptions all work the same as if this attribute wasn't there.

  • DebuggerStepThrough
    This respects breakpoints and will break on exceptions where they occur, but you cannot manually step into blocks marked with this attribute.

  • DebuggerHidden
    This doesn't allow you to step in to these blocks, it ignores breakpoints, and any exceptions thrown are handled in the calling method, not where they actually occur.

When Just My Code is checked

  • All three attributes behave the same as if you had used DebuggerHidden above.

There's another attribute, DebuggerStepperBoundary that is pretty cool. Here's the excerpt from MSDN:

Use the DebuggerStepperBoundaryAttribute to escape from stepping through code to running code. For example, in Visual Studio 2005, encountering a DebuggerStepperBoundaryAttribute while stepping through code using the F10 key (or Step Over command) has the same effect as pressing the F5 key or using the Start Debugging command.

Hope this clears things up! Sure did for me!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!