ProgrammingHardProduct-company placement · C++

What happens when this is compiled?

What happens when this is compiled?
int main() {
    try { throw 1; }
    catch (...) { cout << "any"; }
    catch (int) { cout << "int"; }
}
  1. A. It prints any
  2. B. It prints int
  3. C. It prints anyint
  4. D. Compile-time error: catch (...) must be the last handler

Correct answer: D. Compile-time error: catch (...) must be the last handler

The catch-all handler must come last in its try block; placing a handler after it is ill-formed (it could never be reached).

More OOP with C++ and Java questions

Exams that ask this topic