How can I break on an unhandled exception in ASP.N

2020-02-11 21:31发布

When debugging an application in Visual Studio, there are 2 options for breaking on exceptions. Break as soon as an exception is thrown, and breaking only when an exception isn't caught. This works fine when developing desktop applications. However, when developing ASP.NET applications, all exceptions are eventually caught by the code in IIS. Is it possible to disable this behavior, so that the debugger breaks when my ASP.Net application code fails to catch an exception?


Edit:

Just to be clear, I don't want to break whenever an exception is thrown, as many times they are handled just fine by my code, and I don't want to stop on every exception. I only want to stop on the exceptions that aren't handled by my code.


Edit:

This seems to not be an issue in Visual Studio 2008. In Visual Studio 2003, all exceptions were treated as user handled, because the ASP.NET runtime caught all the exceptions so as not to bring down the web server process. It seems that in Visual Studio 2008, this type of exception catching is not counted when checking for user-unhandled exceptions.

1条回答
疯言疯语
2楼-- · 2020-02-11 21:46

Under Debug->Exceptions, check the 'Thrown' column of Common Language Runtime Exceptions (at a minimum). Check 'Thrown' for other Exceptions you're interested in.

Now, if the debugger is attached (active debug or 'Attach to Process'), your ASP.NET app will break on a CLR Exception (or any other Exception you've selected).

[EDIT]

If you want to break only on unhandled Exceptions, under Debug->Exceptions, uncheck 'Thrown' on all Exception types and make sure 'User-unhandled' is checked for the Exceptions you're interested in.

Exception Interface

Then, if the debugger is attached, your ASP.NET app will break on every User-unhandled Exception you've selected regardless of the fact the runtime will eventually catch the Exception. Sample:

Debugger breaking on User-unhandled exception

查看更多
登录 后发表回答