When you turn on “Break when an exception is thrown” in the Visual Studio debugger, it breaks everywhere for the selected exception types. A way to say so as not to break a specific method: decorate these methods with the DebuggerStepThrough (or DebuggerHidden ) attribute .
This, apparently, for some reason does not work for the async method. Here is a snippet that reproduces the problem. The debugger will be broken inside TestAsync , even if it is marked with attributes, and it will not be broken inside Test as excluded (the only difference between them is the first one marked with the async ):
public class Attributes { public async Task Run() { await TestAsync(); await Test(); } [DebuggerHidden] [DebuggerStepThrough] public async Task TestAsync() { try { throw new Exception("Async"); } catch { } await Task.Delay(100); } [DebuggerHidden] [DebuggerStepThrough] public Task Test() { try { throw new Exception("sync"); } catch { } return Task.Delay(100); } }
So is this behavior intended? This is mistake? Is there any workaround?
i3arnon Jun 26 '14 at 2:35 a.m. 2014-06-26 14:35
source share