open Online C++ Compiler and enter below source code
#include <iostream>
using namespace std;
int main ()
{
int a,b,x ;
cout << " enter values of a and b \n ";
cin >> a;
cin >> b;
x=a-b;
try
{
if( x != 0 )
{
cout <<" Result a/x =" << a/x;
}
else
{
throw (x);
}
}
catch(int y)
{
cout << " Exception caught x= " << x << endl;
}
cout << "\n end";
return 0;
}
output 1:
enter values of a and b
12
6
Result a/x =2
end
output 2:
enter values of a and b
10
10
Exception caught x= 0
end
0 Comments
Post a Comment