#include <iostream>
using namespace std;
int sum(int a,int b) throws (int,char)
{
if(a<0 && b<0)
throw 0;
cout<<(a+b)<<endl;
}
int main()
{
int age;
cout<<"Enter age?";
cin>>age;
try{
if(age<0)
throw 0;
else
if(age>100)
throw 'x';
else
if(age==0)
{
throw 0.0;
}
else
if(age==100){
throw "oho!";
}
cout<<"Age = "<<age<<endl;
}
catch(char ch) //handler prog
{
cerr<<"Illegal age";
}
catch(int ch) //handler prog
{
cerr<<"Age can't be negative";
}
catch(float f){
cerr<<"Age can't be zero";
}
catch(char *str){
cout<<str;
}
catch(...) //default handler
{
cout<<"Unknown error "<<endl;
}
return 0;
}
---------------------------------------------------------------------------------
void pointer example
#include <iostream>
using namespace std;
int main(void)
{
int no=100;
float f=10.345F;
void*n;
n=&f;
cout<<*(float*)n<<endl;
return 0;
}
No comments:
Post a Comment