Exceptions not thrown in web api - visual-studio

I'm using Web Api and when an exception happens in my code (for example a bad cast), and the debugger is attached, the exception is not thrown in Visual Studio. I just get the 500 internal server error on the browser side with the exception details but it's a pain because I have to track down what line it's thrown on.
I don't believe this was always the case, and thought it must be one of my settings messed up but I have already tried to reset visual studio settings to no avail.
How can I get the debugger to break again on 500 internal server errors.. I don't want to enable first chance exceptions.

Tools -> Options -> Debugging -> General, Ensure that "Enable Just My Code" is checked.

In visual studio Debug->Exceptions for exceptions that you need or for all of them select checkbox in the Throw column. It's because by default Asp.Net runtime handles all exceptions. MSDN

Related

Visual Studio Error display

How can the errors in Visual Studio be displayed as in this image:
instead of using the Error List?
The exceptions I get are displayed like this:
(The images are from: How to tell the debugger to ignore breaking on thrown exceptions?, Where did my Visual Studio exception assistant go?)
If you look under Tools | Options in the Debugging | General node, be sure your "Enable the Exception Assistant" is checked.
The error message that is displayed in the first picture is a message displayed for .Net exceptions. (Anything that inherits from System.Exception)
The .Net exception class has members that include data and stack trace that can be displayed nicely and the Visual Studio IDE displayes it for you.
Native errors (from native code or windows code, anything not .Net) is displayed with the second window.
Native exceptions to contain a minimal what() string. Sometimes. But any other class type can be thrown too, so there's not always that much information.

Exceptions Not Being Thrown In Visual Studio

For some reason my exceptions arent being thrown anymore in Visual Studio. I get the error in JSON on the response, but Visual Studio in debug mode no longer throws an error and stops Visual Studio at that error when it happens.
I have looked into posts like this:
Visual Studio not stopping on an exception being thrown
But I just want to reset where I was before, not enable exceptions one by one.
To reset the exceptions settings, go to Debug>Exceptions and click "Reset All."
You can also drill down and control what happens for different types of exceptions.
update
You mentioned that you are missing the User-Unhandled column. In that case, you may need to set this:
Cntrl + Alt + E (Or Debug -> Exceptions)
Then select "Reset All", that will return the default exceptions on.
I hit a problem where it wasn't stopping on an exception and resetting the exception settings worked for me. To expand on Jay's answer above, in VS 2019 that option to reset is in a slightly different place (arguably a step backward compared to how it was before, it's clearer there).
Go to debug -> windows -> exception settings
The reset button is now this icon here:

A first chance exception of type 'StructureMap.StructureMapException' occurred in StructureMap.DLL

Hello I'm getting this exception thrown at me whenever I try to test a web application via visual studio, any ideas why? I'm building a project using MVC3 model and visual studio 2010
Exception: A first chance exception of type 'StructureMap.StructureMapException' occurred in StructureMap.DLL
First chance exceptions might occur while debugging. They might be handled properly by your code and never propagate when running the application normally but nevertheless Visual Studio shows them in Debug mode. If you don't want to be bothered you could disable them in Visual Studio and they will no longer appear.

Visual Studio: What happened to the "Break when an exception is unhandled" option?

As far as I remember, Visual Studio (both 2008 and 2010) used to have an option to break either on thrown exceptions or on unhandled exceptions. Now when I bring up the Exceptions dialog (Ctr+Alt+E), it just offers to break when an exception is thrown:
I've tried resizing to the columns in that dialog, but that did not help. Is this a bug, or am I missing something?
This seems to indicate it can occur if you don't have "Enable Just My Code (Managed Only)" enabled.
Edit: just tried it here (VS 2008) and I can verify that disabling that option will cause the User-Unhandled column to disappear. You can find the option here: Tools -> Options -> Debugging -> General
I have this as well when I've enabled source-server support in VS.NET.
When I have source-server support disabled, then the option to break on unhandled exceptions is still visible.
But, a thought: is it necessary to be able to specify that the IDE should break when an exception is unhandled ? As far as i know, this is just default behaviour, isn't it ? So, what's the use to be able to specify that option ?

Visual Studio Just-In-Time Debugging Annoyances

I have a solution comprising of about 6 projects, and when I debug on one machine, any un-handled exceptions that occur cause the environment to break at the point that exception is thrown, allowing me to debug it.
However, on a different machine with the same solution (in the same version of VS), all I get when an exception is thrown is the "Visual Studio Just-In-Time debugging" window popping up, which tells me the name of the exception, and little else - it offers to open a new visual studio instance in order to debug it, but that doesn't work, because it is already being debugged by the IDE!
What is going on, and how can I get back to visual studio telling me where the exception happened?
Cheers
You might want to check Exceptions in the Debug menu (mapped by default to Ctrl+Alt+E) and verify that both machines have the same exceptions selected.
Probably on the second machine you have less exception types selected in that window. When one of the exceptions that are not selected is thrown:
the debugger does not handle it because it has been instructed not to
the exception gets passes to the OS
the OS launches the default system-wide debugger which is the "Visual Studio Just-In-Time debugging" launcher if you installed VS2005 on that machine.
Sounds like it can't find the debug info.
Try copying the PDB files to your output directory.
I've had this problem as well - two machines, identical exception settings, different behaviours. The solution for me was to set the Debugger Type in the project properties on the "bad" machine to Mixed, even though the application only contains managed code. On the "good" machine exceptions are caught in Visual Studio using the Managed Only setting.

Resources