-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: DebuggerDisableUserUnhandledAttribute #103105
Comments
I assume the intent is that it would control the default behavior of the debugger for "break when an exception of this type is thrown"? IOW, if the exception still goes unhandled, I'd think the debugger would still break at that point? |
(applying labels to ensure it's high on our backlog) |
Tagging subscribers to this area: @tommcdon |
I'm unclear as to what the state of this proposal is. Is this a feature that the VS debugger has already agreed to, and we're just talking about API name? Or is this actually proposing a feature that still needs agreement / design / etc. at the debugger level? |
namespace System.Diagnostics;
[AttributeUsage(AttributeTargets.Method)]
public sealed class DebuggerDisableUserUnhandledExceptionsAttribute : Attribute
{
public DebuggerDisableUserUnhandledExceptionsAttribute();
}
public partial class Debugger
{
public static void BreakForUserUnhandledException(Exception exception);
} |
Background and motivation
In .NET 9, Visual Studio is adding support for catching async user-unhandled exceptions which will be enabled by default. This feature has existed for a long time for synchronous methods, but not for async methods. There are several exceptions in ASP.NET Core that propagate through user code but are expected to be handled by framework code. One example is the
NavigationException
used to force redirects when callingNavigationManager.NavigateTo()
during static Blazor rendering.The proposal is to add an attribute that can be added to framework methods that handle exceptions that propagate through user code like Blazors
NavigationException
and aDebugger
method that these attributed framework methods can use to indicate the exception should really be treated as user unhandled. This gives the framework the opportunity to do runtime checks on the exception and run it through dynamic filtering logic before deciding if the exception should really be considered user-unhandled.API Proposal
API Usage
Alternative Designs
If other frameworks or libraries do not need this, the VS debugger could special case these ASP.NET Core exceptions.
It might also be easier in some cases for framework and library developers if they could add an attribute to the
Exception
type itself if it's a type should always be handled by the framework like Blazor's NavigationException.However, this might be too inflexible because it's all or nothing in terms of whether a given exception type should be considered "user unhandled" regardless of what method threw it or what non-user methods are on the stack that could handle it. This would not work as well as the primary proposal when the exception is handled by an exception "filter" or "handler" that's called after the exception is caught and therefore is not on the stack.
Risks
This use case may be too niche to warrant new runtime API. This might also make it more confusing to developers who expect the debugger to break every user-unhandled exception propagating through user code even if the framework gracefully handles it.
@gregg-miskelly
The text was updated successfully, but these errors were encountered: