Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include <iostream>
    #include <typeinfo>
    using namespace std;
    class Poly
    {
    virtual void Member(){}

    };
    int main ()
    {
    try
    {
    Poly * ptr = 0;
    typeid(*ptr);
    }
    catch (exception& ex)
    {
    cout << "An Exception caught: " << ex.what() << endl;
    }
    return 0;
    }
    1. An Exception caught: std::bad_alloc
    2. An Exception caught: std::bad_cast
    3. An Exception caught: std::bad_typeid
    4. All of above
    5. None of these
Correct Option: C

In this program, We used a bad type id for the polymorphic operator, So it is arising an bad_typeid exception.



Your comments will be displayed only after manual approval.