Write a c++ program to implement exception handling

#include <iostream>

using namespace std;

double division(int a, int b) {

   if( b == 0 ) {

      throw “Division by zero condition!”;

   }

   return (a/b);

}

int main () {

   int x ;

cout<<”x= “;

cin>>x;

   int y ;

cout<<”y= “;

cin>>y;

   double z ;

   try {

      z = division(x, y);

      cout << z << endl;

   }catch (const char* msg) {

      cerr << msg << endl;

   }

   return 0;

}

Output

X= 25

Y=0

Division by zero condition!

Leave a Comment

Your email address will not be published. Required fields are marked *