开发者

commands after try..catch don't work

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 开发者_JAVA技巧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


Your if statement is almost certainly wrong. You're assigning FALSE to bSilenClose and then checking if it (false) is true, which will cause the body of your if 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.

if(m_pDoc->m_bSilenClose = FALSE );
                         ^       ^^^^ This should not be there. (Empty statement after if)
                         ^
                         ^ Assigning FALSE (should be == to test)
                           Condition always FALSE (thus never executes empty statement.


catch will only be called if an exception occurs. As to why the stuff in the if statement isn't being called, either:

  • your conditional statement is wrong
  • your catch might be throwing an exception too (?)

Edit: just noticed this is C++.


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 ;)


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

if(m_pDoc->m_bSilenClose = FALSE ); 

should be:

if(m_pDoc->m_bSilenClose == FALSE ); 


That's why i prefer doing

if ( FALSE == variable )

When comparing to a constant

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜