Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include <iostream>
    #include <exception>
    using namespace std;
    void Function()
    {
    cout << "Unexpected handler called\n";
    throw;
    }
    void NewFunction () throw (int,bad_exception)
    {
    throw 'U';
    }
    int main (void)
    {
    set_unexpected (Function);
    try
    {
    NewFunction();
    }
    catch (int)
    {
    cout << "caught int\n";
    }
    catch (bad_exception be)
    {
    cout << "Caught Bad_exception\n";
    }
    catch (...)
    {
    cout << "Caught other exception \n";
    }
    return 0;
    }
    1. Unexpected handler called
    2. Unexpected handler called
      Caught Bad_exception
    3. Caught Bad_exception
    4. Caught Bad_exception
      Unexpected handler called
    5. None of these
Correct Option: B

In this program, We are calling set_unexpected and NewFunction, So it is printing the output.



Your comments will be displayed only after manual approval.