为什么 try catch 有时会被忽略?
Why is try catch sometimes ignored?
一个例子是这段代码:
try
{
string domain = o.SelectToken("response[" + i + "].domain").ToString();
...
}
catch(Exception)
{
continue;
}
而不是仅仅在循环中继续(“继续”),vs 停止并指向 string domain = o.SelectToken("response[" + i + "].domain").ToString();
以获得 System.IndexOutOfRangeException
。
这是为什么?
您可能在调试>Windows>异常设置中选择了 'break on all exceptions':
取消选择此项将使 VS 继续。
您可以通过两种方式完成。
按照 MSDN 中的建议,在您的Visual Studio(我相信是 2019 年)
中进行设置
调试>Windows>异常设置:搜索index 并取消勾选。
请在您的代码中添加异常以处理异常..
catch(IndexOutOfRangeException e)
{
// handle it like logging it in file and continue
continue;
}
catch(Exception)
{
continue;
}
一个例子是这段代码:
try
{
string domain = o.SelectToken("response[" + i + "].domain").ToString();
...
}
catch(Exception)
{
continue;
}
而不是仅仅在循环中继续(“继续”),vs 停止并指向 string domain = o.SelectToken("response[" + i + "].domain").ToString();
以获得 System.IndexOutOfRangeException
。
这是为什么?
您可能在调试>Windows>异常设置中选择了 'break on all exceptions':
取消选择此项将使 VS 继续。
您可以通过两种方式完成。
按照 MSDN 中的建议,在您的Visual Studio(我相信是 2019 年)
中进行设置调试>Windows>异常设置:搜索index 并取消勾选。
请在您的代码中添加异常以处理异常..
catch(IndexOutOfRangeException e) { // handle it like logging it in file and continue continue; } catch(Exception) { continue; }