Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    double DivFunction(int num1, int num2)
    {
    if ( num2 == 0 )
    {
    throw "Division by zero condition Occurred...";
    }
    return (num1 / num2);
    }
    int main ()
    {
    int m = 10;
    int n = 0;
    double Res = 0;
    try
    {
    Res = DivFunction(m, n);
    cout << Res << endl;
    }
    catch (const char* msg)
    {
    cout << msg << endl;
    }
    return 0;
    }
    1. Compilation Error
    2. Runtime Error
    3. Division by zero condition Occurred...
    4. Garbage value
    5. None of these
Correct Option: C

We are dividing the values and if one of the values is zero means, We are arising an exception.



Your comments will be displayed only after manual approval.