Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    void Example(int n)
    {
    try
    {
    if (n > 0)
    throw n;
    else
    throw 'L';
    }
    catch(char)
    {
    cout << "Catch a integer and that integer is :" << n;
    }
    }
    int main()
    {
    cout << "Testing multiple catches :";
    Example(5);
    Example(0);
    }
    1. Catch a integer and that integer is : 5
    2. Compilation Error
    3. Testing multiple catches :
    4. Runtime Error
    5. None of these
Correct Option: C

As the catch is created with a wrong type, So it will arise a runtime error.



Your comments will be displayed only after manual approval.