Search This Blog

Tuesday, May 10, 2011

Exception Handling


Introduction –
Role of a Library Programmer -While defining non-member function or non-member function, a function may / may not be able to execute further.
 
 
 
 
nLets see a function hmean( ) that takes 2 float type numbers as parameters and computes their harmonic mean.
float hmean(const float a, const float b)
{
if (a==b)
{
abort();
return 2.0*a*b/(a+b);
}
} Code for Function to compute harmonic mean
 
int hmean(const double a, const double b, double const *c)
{
if (a==-b)
{
c=0;
return 0; //return failure
}
else
{ C=2.0*a*b/(a+b);
return 1; //return success
}