Exception Handling in oops || C++
In this, we are going to see a program on Exception Handling in oops in C++ Programming Language.



The Code given below can be used in gcc/g++ Compilers: -

#include <iostream>
using namespace std;

double zeroDivision(int x, int y)
{
    if (y == 0)
    {
        throw "Division by Zero!";
    }
    return (x / y);
}

int main()
{
    int a = 11;
    int b = 0;
    double c = 0;
    try
    {
        c = zeroDivision(a, b);
        cout << c << endl;
    }
    catch (const char *message)
    {
        cerr << message << endl;
    }
    return 0;
}

#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post