Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

commands after try..catch don't work

Tags:

c++

mfc

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

like image 435
user641490 Avatar asked Mar 14 '26 14:03

user641490


2 Answers

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.
like image 189
Mark B Avatar answered Mar 16 '26 03:03

Mark B


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++.

like image 24
jonnii Avatar answered Mar 16 '26 03:03

jonnii



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!