Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include <stdexcept>
    #include <limits>
    #include <iostream>
    using namespace std;
    void Function(int ch)
    {
    if (ch < numeric_limits :: max())
    throw invalid_argument("Function argument too large.");
    else
    {
    cout<<"Programs Executed...";
    }
    }
    int main()
    {
    try
    {
    Function(150);
    }
    catch(invalid_argument& excep)
    {
    cout << excep.what() << endl;
    return -1;
    }
    return 0;
    }
    1. Function argument too large.
    2. Compilation Error
    3. Programs Executed...
    4. Runtime Error
    5. None of these
Correct Option: C

As we are throwing the function and catching it with a correct data type, So this program will execute.



Your comments will be displayed only after manual approval.