Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    double Div(int num1, int num2)
    {
    if (num2 == 0)
    {
    throw "Division by zero condition!";
    }
    return (num1 / num2);
    }
    int main ()
    {
    int p = 25;
    int q = 0;
    double Res = 0;
    try
    {
    Res = Div(p, q);
    cout << Res << endl;
    }
    catch (const Message)
    {
    cerr << Message << endl;
    }
    return 0;
    }
    1. Compilation Error
    2. 25
    3. Runtime Error
    4. Division by zero condition!
    5. None of these
Correct Option: A

As we missed the data type in the catch block, It will arise an error.



Your comments will be displayed only after manual approval.