elau89
BAN USERI'm not sure if this is particular to any language, but I see this in the C++ section, so I'll answer accordingly.
1. A number of things may have happened in func(). I would check out the call stack and make sure that the function was the last thing that called. Once I have confirmed that, I would investigate and make sure func() does not throw any exceptions or get caught in an infinite loop (or any other basic errors like referencing nulls). There is a possibility of a deadlock (but only in the case if there is a static or member mutex).
2. Again, we do not know for sure what has happened in func() with what is given, but due to the nature of this question, the interviewer is probably implying that func() has thrown an exception.
3. In C++, the correct way to handle this is through the use of RAII. A number of solutions will work including scoped locks, mutex with functors, or narrowing the scope of that lock to known parts of code where you KNOW exceptions will not be thrown. A try/catch will not help you in C++. However, in Java, simply use a try/finally block to ensure forward movement in the code.
Actually, ยง5.3.2.1 states "The operand of prefix ++ is modified by adding 1, or set to true if it is bool (this use is deprecated). The
- elau89 March 02, 2015operand shall be a modifiable lvalue."
postfix ++ is a prvalue though, so it can not be modified.