Question discussion

What is the output of the following C++ program?#include using namespace std; void f() { try { throw 1; } catch (int) { cout

1187Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C++ program?

#include <iostream>
using namespace std;
void f() {
    try { throw 1; }
    catch (int) { cout << "A"; throw; }
}
int main() {
    try { f(); }
    catch (int x) { cout << "B" << x; }
    cout << "C";
}
  • AA1BC
  • BAB1C
  • CAC
  • DB1C
Correct answer: B

Explanation

f() prints A and re-throws the same exception; main catches it and prints B1, and execution continues to print C.

Discussion 0

Nobody has replied yet. Start the discussion!