C++ Try Catch 内循环 [英] C++ Try Catch inside loop
问题描述
我有一个具有以下一般结构的 C++ 程序
I have this C++ program with the following general structure
1st while (condition A == true)
//some code for 1st loop
2nd while (condition B == true)
//some code for 2nd loop
try
//some code for try
catch
//condition B == false (supposed to leave 2nd loop and go back to first loop)
我希望它在出现异常时退出第二个循环并返回到第一个循环,直到条件 B 再次出现.如上所述,它不像我预期的那样工作.似乎正在发生的事情是代码卡在 catch
中并且永远不会离开它.
I want it to get out of 2nd loop when there's an exception and go back to 1st loop until condition B is tue again. As described above it doesn't work as I expect. What seems to be happening is that code gets stuck in catch
and never leaves it.
我如何安排它以使其按照我的需要工作?
How can I arrange it to make it work as I need?
注意:条件 A 永远不会为假.
Note: condition A is never false.
推荐答案
在 catch 中添加 break 关键字
add the break keyword to the catch
还要注意你有 b == false;那就是检查 b 是否等于 false,而不是设置 b = false.
Also notice that you have b == false; That is checking that b is equal to false, not setting b = false.
这篇关于C++ Try Catch 内循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!