Reputation: 51
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
Upvotes: 2
Views: 441
Reputation: 3442
That's why i prefer doing
if ( FALSE == variable )
When comparing to a constant
Upvotes: 0
Reputation: 96241
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.
Upvotes: 6
Reputation: 14471
You have a typo
if(m_pDoc->m_bSilenClose = FALSE );
should be:
if(m_pDoc->m_bSilenClose == FALSE );
Upvotes: 0
Reputation:
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 ;)
Upvotes: 1
Reputation: 308206
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.
Upvotes: 0
Reputation: 28312
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++.
Upvotes: 4