1 Answers
Code:
#include <iostream>
using namespace std;
int main()
{
float a,b;
cout<<“Enter values of a and b \n”;
cin>> a;
cin >> b;
float x = a-b;
try
{
if(x !=0 )
{
cout<<“Result (a/x) = ” << a/x << “\n”;
}
else
{
throw(x);
}
}
catch(float i)
{
cout<<“Exception caught : DIVIDE BY ZERO”;
}
cout<<“\nEND” << endl;
return 0;
}
Output:
Enter values of a and b
12
10
Result (a/x) = 6
END
Enter values of a and b
10
10
Exception caught: DIVIDE BY ZERO
END