
Exception Handling: Show Must Go On! 343
try
{
if(height <=0 )
throw exception();
}
catch(exception & e)
{
cout<<"Enter correct height"<<endl;
cout<<"Earlier value of height is:"<<this->height<<endl;
cin>>this->height;
}
}
void DeterminePurity()
{
fl oat v,d;
v=getVolume();
d=getDensity(v);
if(d==accurate_density)
cout<<"Metal "<< metalType<<" is pure."<<endl;
else
cout<<"Metal "<< metalType<<" is not pure."<<endl;
}
};
int main()
{
CuboidMetal c1("Silver",0,9.5,2.8,2793,10.5);
CuboidMetal c2("Gold",7.1,5.8,9.1,7103,19.3);
CuboidMetal c3("Platinum",10,9.5,2.8,5400,21.4);
MetalShape* ptr[3]={&c1,&c2,&c3 };
for(int i=0;i<3;i++)
ptr[i]->DeterminePurity(); ...