try..catch 之后的命令不起作用
我有一个带有 try..catch 的方法。 结构是这样的:
try
{
commands...
}
catch(...)
{
ERROR(...);
}
if(m_pDoc->m_bS = FALSE ) // Check here if AutoLogout event occurred.
StartCollect();
}
程序不会进入catch部分,但后面也不会进入if语句。 可能是什么问题?为什么程序不执行if语句?
谢谢
I have a method with try..catch.
the structure is like this:
try
{
commands...
}
catch(...)
{
ERROR(...);
}
if(m_pDoc->m_bS = FALSE ) // Check here if AutoLogout event occurred.
StartCollect();
}
The program doesn't go into the catch section, but it also doesn't go into the if statement later.
What can be the problem? Why doesn't the program go to the if statement?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您的
if
语句几乎肯定是错误的。您将FALSE
分配给bSilenClose
,然后检查它 (false) 是否为 true,这将导致if
的主体永远不会执行。在 C++ 中,相等性测试是==
。此外,正如 @Martin York 指出的那样,尾随的;
将被视为 if 的主体。事实上,下面大括号中的代码应该每次都执行。Your
if
statement is almost certainly wrong. You're assigningFALSE
tobSilenClose
and then checking if it (false) is true, which will cause the body of yourif
to never execute. In C++ the test for equality is==
. Additionally as @Martin York points out, the trailing;
will be treated as the body of your if. The code below in braces should, in fact, execute every time.catch
仅在发生异常时才会被调用。至于为什么 if 语句中的内容没有被调用:编辑:刚刚注意到这是 C++。
catch
will only be called if an exception occurs. As to why the stuff in the if statement isn't being called, either:Edit: just noticed this is C++.
你抓到了什么?您的错误可能是您尝试捕获的错误之外的另一种类型。此外,Catch 可能会引发异常。
真实的代码和更好的描述也总是有帮助的;)
What do you catch? Your error could be of another type than the error you try to catch. Also, the Catch might be throwing an exception.
Real code and a better description always help too ;)
逐行浏览调试器中的代码块(使用 F10 键)。您应该看到代码确实到达了
if
语句。Go through the block of code in the debugger, line by line (use the F10 key). You should see that the code does indeed get to the
if
statement.你有一个错字
应该是:
You have a typo
should be:
这就是为什么我更喜欢
使用if ( FALSE == variable )
在与常量进行比较时
That's why i prefer doing
if ( FALSE == variable )
When comparing to a constant