Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    int main()
    {
    int num = -2;
    char *p;
    p = new char[50];
    try
    {
    if (num < 0)
    {
    throw num;
    }
    if (p == NULL)
    {
    throw "p is NULL ";
    }
    }
    catch (...)
    {
    cout << "Exception occurred: exiting"<< endl;
    }
    return 0;
    }
    1. Compilation Error
    2. Runtime Error
    3. p is NULL
    4. Exception occurred: exiting
    5. None of these
Correct Option: D

catch(…) is used to catch all types of exceptions arising in the program.



Your comments will be displayed only after manual approval.