Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    void DivFunction(const double num1, const double num2);
    int main()
    {
    double option1=20, option2=5;
    try
    {
    DivFunction(option1, option2);
    }
    catch (const char* S)
    {
    cout << "Bad Operator caught: " << S;
    }
    return 0;
    }
    void DivFunction(const double num1, const double num2)
    {
    double Res;
    if (num2 == 0)
    throw "Division by zero not allowed";
    Res = num1 / num2;
    cout << Res;
    }
    1. Bad Operator caught
    2. Division by zero not allowed
    3. 10
    4. 20
    5. 4
Correct Option: E

We are dividing 20 and 5 in this program and we are using the throw statement in the function block.



Your comments will be displayed only after manual approval.