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(char ch)
    {
    if (ch < numeric_limits::max())
    return invalid_argument;
    }
    int main()
    {
    try
    {
    Function(50);
    }
    catch(invalid_argument& excep)
    {
    cout << excep.what() << endl;
    return -1;
    }
    return 0;
    }
    1. Invalid argument
    2. 50
    3. Compilation Error
    4. Runtime Error
    5. None of these
Correct Option: C

We can’t return a statement by using the return keyword, So it is arising an error.
Compilation Error

In function 'void MyFunc(char)':
8:36: error: expected primary-expression before ';' token
8:36: error: return-statement with a value, in function returning 'void' [-fpermissive]
In function 'int main()':
14:23: warning: overflow in implicit constant conversion [-Woverflow]



Your comments will be displayed only after manual approval.