Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include <iostream>
    #include <exception>
    using namespace std;
    class ExceptionExample: public exception
    {
    virtual const char* what() const throw()
    {
    return "Exception Occurred...";
    }
    } NewExcep;
    int main ()
    {
    try
    {
    throw NewExcep;
    }
    catch (exception& excep)
    {
    cout << excep.what() << endl;
    }
    return 0;
    }
    1. Compilation Error
    2. Runtime Error
    3. Exception Occurred...
    4. Garbage value
    5. None of these
Correct Option: C

In this program, We are arising a standard exception and catching that and returning a statement.



Your comments will be displayed only after manual approval.