#include <iostream>
using namespace std;
class exception1
{
int car,age;
char city[20];
public:
void getdata()
{
cout<<"enter the age"<<endl;
cin>>age;
cout<<"enter the number of cars"<<endl;
cin>>car;
cout<<"enter the city"<<endl;
cin>>city;
}
void checkcondition()
{
try
{
if(age<18||age>60)
{
throw "age should be in 18 and 60";
}
} catch (const char * msg)
{
cerr<<msg<<endl;
}
try
{
if(car!=4)
{
throw "car should be 4";
}
} catch (const char * msg)
{
cerr<<msg<<endl;
}
try
{
if(city=="pune"||city=="Pune")
{
}
else
{
throw "city should be pune";
}
} catch (const char * msg)
{
cerr<<msg<<endl;
}
}
};
int main()
{
exception1 handling;
handling.getdata();
handling.checkcondition();
return 0;
}
To embed this program on your website, copy the following code and paste it into your website's HTML: