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

What will be the output of the following C++ code?
Code:
#include <iostream>
using namespace std;
int main()
{
    try
    {
        try
        {
            throw 20;
        }
        catch (int 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: a
Explanation: As exception thrown by the inner try block is caught by the inner catch block hence the exception is handled at the inner level and program continues to run outer try block, statement afterwards.
 

Tìm kiếm

Back
Top