如果我有一个嵌套循环的场景,并且我在调试模式下单步执行它。例如:
for (int i = 0; i < listTest.Count; i++)
{
for (int j = 0; j < anotherList.Count; j++)
{
//Some logic that throws an exception
}
}有没有办法让我在异常发生前知道i, j, listTest[i] and anotherLIst[j]的值?如果计数值很高,那么在异常发生之前遍历循环并观察这些值是不切实际的
发布于 2009-07-17 19:36:34
首先,您可以更改VS2008中的设置,以便在抛出异常时中断:
Debug >> Exception >> Common Language Runtime Exceptions Dialog这将导致调试器在生成违规异常的代码行处停止,此时i和j应该在作用域中。
您还可以将循环变量i和j提升到循环之外;如下所示:
int i, j;
for (i = 0; i < listTest.Count; i++)
{
for (j = 0; j < anotherList.Count; j++)
{
//Some logic that throws an exception
}
}https://stackoverflow.com/questions/1145203
复制相似问题