Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    int main()
    {
    int a = 8;
    try
    {
    if (a < 0)
    throw "Positive Number Required";
    cout << a << "\n\n";
    }
    catch(const char* Msg)
    {
    cout << "Error: " << Msg;
    }
    return 0;
    }
    1. Positive Number Required
    2. 8
    3. Compilation Error
    4. Runtime Error
    5. None of these
Correct Option: B

In this program, We are checking the age of a person, If it is zero means, We will arise a exception.



Your comments will be displayed only after manual approval.