Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include <iostream>
    #include <exception>
    #include <typeinfo>
    using namespace std;
    class Sample
    {
    virtual int Function()
    {
    }
    };
    int main ()
    {
    try
    {
    Sample *ptr = NULL;
    typeid (*ptr);
    }
    catch (std::exception& TypeVar)
    {
    cout << "Exception Occurred: " << TypeVar.what() << endl;
    }
    return 0;
    }
    1. Compilation Error
    2. Null
    3. Exception Occurred: std::bad_alloc
    4. Exception Occurred: std::bad_typeid
    5. None of these
Correct Option: D

As we are using a bad type on pointers, So it is arising an error.



Your comments will be displayed only after manual approval.