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 called\n";
    throw 0;
    }
    void myfunction () throw (int)
    {
    throw 'L';
    }
    int main ()
    {
    set_unexpected (Function);
    try
    {
    myfunction();
    }
    catch (int)
    {
    cout << "Caught int\n";
    }
    catch (...)
    {
    cout << "caught other exception\n";
    }
    return 0;
    }
    1. Caught int
    2. Unexpected called
      Caught int
    3. Unexpected called
    4. Caught int
      Unexpected called
    5. None of these
Correct Option: B

As we are calling set_unexpected (myunexpected) function, this is printing as unexpected called and because of operator compliance it is arising an exception.



Your comments will be displayed only after manual approval.