简体   繁体   English

为什么 Visual Studio 不会因未处理的外部异常而中断?

[英]Why doesn't Visual Studio break on unhandled external exceptions?

I'm using Visual Studio 2017 (15.4.1) while developing an ASP.NET Core MVC 2 application running on .NET Framework 4.6.2.我正在使用 Visual Studio 2017 (15.4.1) 开发在 .NET Framework 4.6.2 上运行的 ASP.NET Core MVC 2 应用程序。

I'm trying to get Visual Studio to break on all unhandled exceptions that pass through my code.我试图让 Visual Studio 中断通过我的代码的所有未处理的异常。 How can I get Visual Studio to break on unhandled exceptions that are thrown in an external library that is called from my code?如何让 Visual Studio 中断从我的代码调用的外部库中引发的未处理异常?

These are my settings:这些是我的设置:

  • Exception Settings -> Break when thrown:异常设置 -> 抛出时中断:
    • All defaults.所有默认值。 This means:这意味着:
      • Don't break when thrown for almost every exception.几乎每个异常都抛出时不要中断。
      • Don't continue when unhandled in user code for almost every exception.对于几乎所有异常,在用户代码中未处理时不要继续。
  • Options -> Debugging -> General:选项 -> 调试 -> 常规:
    • Enable Just My Code启用仅我的代码
    • Use the new Exception Helper.使用新的异常帮助程序。

See the following code snippet:请参阅以下代码片段:

void ThrowExceptionInUserCode()
{
    // Exception helper doesn't pop up, and shouldn't.
    try { throw new Exception(); }
    catch (Exception) { }

    // Exception helper pops up, and should.
    throw new Exception();
}

void ThrowExceptionInExternalLibrary()
{
    // Exception helper doesn't pop up, and shouldn't.
    try { PopularLibrary.MethodThatFails(); }
    catch (Exception) { }

    // Exception helper doesn't pop up, and should.
    // This is the thing I'm trying to get to work.
    PopularLibrary.MethodThatFails();
}

Note that I cannot disable 'Just My Code', because ASP.NET has a default exception handler, which would make all my exceptions handled.请注意,我无法禁用“仅我的代码”,因为 ASP.NET 有一个默认的异常处理程序,它将处理我的所有异常。

Edit: Since my question has been marked duplicate, let me specifiy why its not the same as the other question.编辑:既然我的问题已被标记为重复的,让我specifiy为什么它一样的其他问题。 The other question is more general.另一个问题更笼统。 'Why does Visual Studio not break at all on an unhandled exception. “为什么Visual Studio中并不对未处理的异常中断。 This works perfectly fine for me.这对我来说非常好。 Visual Studio does break on unhandled exceptions. Visual Studio 确实会因未处理的异常而中断。 Visual Studio only does not break on unhandled exceptions thrown from an external library, like my code sample specified. Visual Studio不会中断从外部库引发的未处理异常,就像我指定的代码示例一样。

Secondly the original question has many answers, but non answer the original question.其次,原始问题有很多答案,但没有回答原始问题。 (The original asker even mentions this in the replies.) These other answers solved a different problem for many users, hence the many upvotes. (最初的提问者甚至在回复中提到了这一点。)这些其他答案为许多用户解决了一个不同的问题,因此获得了许多赞成票。

The problem is that ASP.NET Core catches all exceptions to be able to show an error message to the client rather than crashing the HTTP connection.问题在于 ASP.NET Core 捕获所有异常,以便能够向客户端显示错误消息,而不是使 HTTP 连接崩溃。

So technically all exceptions are "handled" and thus not caught by Visual Studio.因此,从技术上讲,所有异常都被“处理”,因此不会被 Visual Studio 捕获。

Ideally Visual Studio unhandled exception code would insert itself before the ASP.NET Core exception handler, but so far it doesn't.理想情况下,Visual Studio 未处理的异常代码会在 ASP.NET Core 异常处理程序之前插入自己,但到目前为止还没有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio 2015打破未处理的异常无效 - Visual Studio 2015 break on unhandled exceptions not working Visual Studio 2010不会停止在Socket.BeginReceive()回调中的未处理异常 - 为什么? - Visual Studio 2010 doesn’t stop at an unhandled exception inside a Socket.BeginReceive() callback - why? 如何在Visual Studio中检测未处理的异常? - How to detect unhandled exceptions in Visual Studio? Visual Studio 2013捕获未处理的异常 - Visual Studio 2013 catching unhandled exceptions TPL打破未处理的异常 - TPL Break on unhandled exceptions visual studio 2008保存或备份异常中断 - visual studio 2008 save or backup exceptions to break on 在Visual Studio 2015中DebuggerStepThrough不再传递异常? - In Visual Studio 2015 DebuggerStepThrough doesn't pass over exceptions anymore? Visual Studio 2017中断异常(也处理异常) - Visual studio 2017 break on throw for exceptions (also handled exceptions) 为什么Visual Studio会中断第三方库中引发和处理的异常? - Why does Visual Studio break on Exceptions thrown and handled in a third party library? Visual Studio 2013“打破处理的异常”不起作用,而不是破坏 - Visual Studio 2013 “break on handled exceptions” not working, not breaking
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM