Get line number of first-chance exception

£可爱£侵袭症+ 提交于 2019-12-23 07:38:16

问题


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?


回答1:


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:



来源:https://stackoverflow.com/questions/10391903/get-line-number-of-first-chance-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!