简体   繁体   中英

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.

I'm trying to get Visual Studio to break on all unhandled exceptions that pass through my code. How can I get Visual Studio to break on unhandled exceptions that are thrown in an external library that is called from my code?

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.

Edit: Since my question has been marked duplicate, let me specifiy why its not the same as the other question. The other question is more general. 'Why does Visual Studio not break at all on an unhandled exception. This works perfectly fine for me. Visual Studio does break on unhandled exceptions. Visual Studio only does not break on unhandled exceptions thrown from an external library, like my code sample specified.

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.

So technically all exceptions are "handled" and thus not caught by Visual Studio.

Ideally Visual Studio unhandled exception code would insert itself before the ASP.NET Core exception handler, but so far it doesn't.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM