Skip to content

Commit d4d65ad

Browse files
authored
Document BreakForUserUnhandledException and DebuggerDisableUserUnhadledExceptionsAttribute (#10406)
1 parent bd6f5b5 commit d4d65ad

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

xml/System.Diagnostics/Debugger.xml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,17 @@ Console.WriteLine("Hello, world.");
218218
<Parameter Name="exception" Type="System.Exception" Index="0" FrameworkAlternate="net-9.0" />
219219
</Parameters>
220220
<Docs>
221-
<param name="exception">To be added.</param>
222-
<summary>To be added.</summary>
223-
<remarks>To be added.</remarks>
221+
<param name="exception">The user-unhandled exception.</param>
222+
<summary>
223+
Signals a breakpoint to an attached debugger with the <paramref name="exception" /> details if a .NET debugger is attached with break on user-unhandled exception enabled and a method attributed with DebuggerDisableUserUnhandledExceptionsAttribute calls this method.
224+
</summary>
225+
<remarks>
226+
<format type="text/markdown"><![CDATA[
227+
228+
## Remarks
229+
This API is designed to be used with <xref:System.Diagnostics.DebuggerDisableUserUnhandledExceptionsAttribute>. If a .NET debugger is attached and the debugger supports breaking on user-unhandled exceptions, this method signals a breakpoint to the debugger with the `exception` parameter.
230+
]]></format>
231+
</remarks>
224232
</Docs>
225233
</Member>
226234
<Member MemberName="DefaultCategory">

xml/System.Diagnostics/DebuggerDisableUserUnhandledExceptionsAttribute.xml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,39 @@
2020
</Attribute>
2121
</Attributes>
2222
<Docs>
23-
<summary>To be added.</summary>
24-
<remarks>To be added.</remarks>
23+
<summary>
24+
If a .NET Debugger is attached that supports the <see cref="M:System.Diagnostics.Debugger.BreakForUserUnhandledException(System.Exception)" /> API, the debugger won't break on user-unhandled exceptions when the exception is caught by a method with this attribute, unless <see cref="M:System.Diagnostics.Debugger.BreakForUserUnhandledException(System.Exception)" /> is called.
25+
</summary>
26+
<remarks>
27+
<format type="text/markdown"><![CDATA[
28+
29+
## Remarks
30+
Visual Studio has added support for catching asynchronous user-unhandled exceptions and it's enabled by default. This feature has existed for a long time for synchronous methods, but not for `async`/`await` methods. The <xref:System.Diagnostics.Debugger.BreakForUserUnhandledException(System.Exception)> method disables the feature for specific methods. This is useful for exceptions that propagate through user code but are expected to be handled by framework code. This attribute is designed to be used along with <xref:System.Diagnostics.Debugger.BreakForUserUnhandledException(System.Exception)>.
31+
32+
## Example
33+
34+
```csharp
35+
[MethodImpl(MethodImplOptions.NoInlining)]
36+
[DebuggerDisableUserUnhandledExceptions]
37+
static async Task InvokeUserCode(Func<Task> userCode)
38+
{
39+
try
40+
{
41+
await userCode();
42+
}
43+
catch (Exception ex)
44+
{
45+
if (TryHandleWithFilter(ex))
46+
{
47+
return; // example case where we don't want to break for user-unhandled exceptions
48+
}
49+
50+
Debugger.BreakForUserUnhandledException(e); // debugger will stop here and show the exception if attached.
51+
}
52+
}
53+
```
54+
]]></format>
55+
</remarks>
2556
</Docs>
2657
<Members>
2758
<Member MemberName=".ctor">

0 commit comments

Comments
 (0)