What will be the output of the following C++ code? [code] #include <iostream> using namespace std; int main() { try {

KellyPoima

New member
What will be the output of the following C++ code?
Code:
#include <iostream>
using namespace std; 
int main()
{
    try
    {
        try
        {
            throw 20;
        }
        catch (char n)
        {
            cout << "Inner Catch\n";
        }
    }
    catch (int x)
    {
        cout << "Outer Catch\n";
    }
    return 0;
}
A. Inner Catch
B. Outer Catch
C.
Inner Catch
Outer Catch
D. Error
 
Answer: b
Explanation: As there is no inner catch handler to handle the int exception thrown by the try block therefore outer catch block handler catches the exception thrown by the inner try catch therefore the output prints "Outer Catch" instead of "Inner Catch". After that program continues execution.
 

Tìm kiếm

Back
Top