Exception Handling Example – C++ Language

#include <iostream>

using namespace std;

int main()
{
int a,b;
cout<<“Enter values of a and b”<<endl;
cin>>a>>b;
int x=(a-b);
try
{
if(x!=0)
{
cout<<“result=”<<(a/(a-b));
}
else
{
throw x;
}
}
catch(int i)
{
cout<<“In division by zero”<<endl;
}
return 0;
}