Saturday, 26 April 2014

exception handling in c++


#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int a,b;
cout<<"enter the values of a and b"<<endl;
cin>>a>>b;
int x=a-b;
try
{
if (x !=0)
{
cout<<"result (a/x) ="<<a/x<<endl;
}
else
{
throw(x);
   }
}
catch(int i)
{
cout<<"exception caught"<<x<<endl;
}
cout<<"END"<<endl;
getch();
return 0;
}

No comments:

Post a Comment