获取第一次机会异常的行号 [英] Get line number of first-chance exception

查看:159
本文介绍了获取第一次机会异常的行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从某个地方收到异常,但是从编译器得到的所有异常都是在mscorlib.dll中发生的System.ArgumentOutOfRangeException类型的第一次异常。这对我来说是相当无用的,因为这不是我的代码(很确定它是默认的库)。我想看到一个堆栈跟踪或一些东西,所以我知道我的代码在哪里出错了。这是一个相当大的代码库(其中大部分不是我的),并且有很多多线程和其他的东西,所以几乎不可能尝试和逐步的代码,而不知道从哪里开始看。有一些设置可以让所有的异常触发一个中断,所以我可以看到调用堆栈发生时,而不是让他们默认地失败,在输出中有一个完全无用的错误消息?

解决方案

你有几个选项。首先,像格雷格说的,当任何异常发生时,你可以导致VS破裂:





确保选中这些选项,然后单击确定:





这将导致另外一种方法是捕获异常并且只写入堆栈跟踪,或者写异常(使用ToString())到输出窗口:





然后检查您的输出窗口:




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:

这篇关于获取第一次机会异常的行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆