Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get line number of first-chance exception

I'm getting exceptions thrown from somewhere, but all I get from the compiler is "A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll". This is fairly useless to me, as that's not my code (pretty sure it's default library). I'd like to see a stack-trace or something so I know where in my code things went wrong. It's a fairly large codebase (much of which is not mine), and there's a lot of multi-threading and other stuff going on, so it's nearly impossible to try and step through the code without some idea of where to start looking. Is there some setting somewhere to make ALL exceptions trigger a break so I can see the call-stack when they occur, rather than just having them silently fail with a completely useless error message in the output?

like image 943
Darrel Hoffman Avatar asked Apr 30 '12 23:04

Darrel Hoffman


People also ask

How do I print line number in exception?

Use sys. exc_info() to retrieve the file, line number, and type of exception.

What is first chance exception?

A first chance exception occurs when an exception is thrown and there is no catch block to handle it. Enablying first chance exceptions stops the debugger whenever an exception is thrown whether there is a catch block or not.

What is first chance exception and second chance exception?

When an application is being debugged, the debugger gets notified whenever an exception is encountered At this point, the application is suspended and the debugger decides how to handle the exception. The first pass through this mechanism is called a "first chance" exception.

What is stack trace in C#?

The execution stack keeps track of all the methods that are in execution at a given instant. A trace of the method calls is called a stack trace. The stack trace listing provides a way to follow the call stack to the line number in the method where the exception occurs.


1 Answers

You have a couple of options. First, like Greg said, you can cause VS to break when any exception occurs:

enter image description here

Make sure these are checked, then click OK:

enter image description here

That will cause Visual Studio to break wherever the exception occurs.

Another approach is to catch the exception and either write just the stack trace, or write the exception (using ToString()) to the output window:

enter image description here

Then check your output window:

enter image description here

like image 95
Bob Horn Avatar answered Sep 22 '22 22:09

Bob Horn