简体   繁体   中英

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?

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

在此输入图像描述

Make sure these are checked, then click OK:

在此输入图像描述

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:

在此输入图像描述

Then check your output window:

在此输入图像描述

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