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.
- All defaults. This means:
- 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.