Sunday, April 12, 2009
EXCEPTION HANDLING PROGRAM
#include
#include
void main()
{
int a,b;
clrscr();
cout<<"\nenter the value a and b:";
cin>>a;
cin>>b;
int x=a-b;
try
{
if(x!=0)
cout<<"\nresult:"<< a/x;
else
throw (x);
}
catch(int i)
{
cout<<"\nexception Caught"<< x;
}
getch();
}
Output will be:
Enter the value a and b: 10 10
Exception Caught 0
EXCEPTION HANDLING
Enter the value a and b: 10 5
Result: 2
#include
void main()
{
int a,b;
clrscr();
cout<<"\nenter the value a and b:";
cin>>a;
cin>>b;
int x=a-b;
try
{
if(x!=0)
cout<<"\nresult:"<< a/x;
else
throw (x);
}
catch(int i)
{
cout<<"\nexception Caught"<< x;
}
getch();
}
Output will be:
Enter the value a and b: 10 10
Exception Caught 0
EXCEPTION HANDLING
Enter the value a and b: 10 5
Result: 2
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
[フレーム]