Sunday, August 29, 2010

Exception Handling in Cplusplus

,
Exception handling:-Exception Handling is used in object oriented programming.It is feature by which we can handle easily a lot of feature.so that u can easily debug the code and to find the where the actual problem reside.In the Exception Handling we can use the try and the catch block
In the try block we can use the code in which the error may be occured that are to be placed in try block.
In the catch block particular error are to be handled in which way.The solution of particular error are provided in the catch block.
Example:-
#include<iostream.h>
int  main()
{
int a,b;
cout<<”Enter Values of a and b\n”;
cin>>a>>b;
int x=a-b;
try
{
If(x!=0)
{
cout<<”Results(a/x)=”<<<”\n”;
}
else
{
 throw(x);
}
}
catch(int i)
{
cout<<”Exception Caught :x=”<<<”\n”;
}
cout<<”END”;
return 0;
}

Output1:-            Enter Values of a and b
                                400       20
Result(a/x)  =   20
END

Enter Values of a and b
                                20           20
Exception Caught:   x =   0
END


0 comments to “Exception Handling in Cplusplus”

Post a Comment