#include <iostream>
#include <stdexcept>
using namespace std;
class Date{
public:
class Invalid{};// A class as exception
Date(int y, int m,int d);
Date():Date(0,1,1){}
int year(){return y;}
int month(){return m;}
int day(){return d;}
private:
int y, m, d;
bool is_valid();
};
Date::Date(int yy,int mm,int dd):y{yy},m{mm},d{dd}
{
if(!is_valid()) throw Invalid{};
}
bool Date::is_valid(){
if(m<1||m>12) return false;
// skip other checkings.
else return true;
}
void f(int m){
try{
Date date {2014,m,2};
cout<<date.month()<<endl;
}
catch(Date::Invalid){
throw invalid_argument("invalid date");
}
}
int main(){
int x=1;
try{
f(x);
f(x+12);
f(x+3);
}
catch(exception & e){
cout<<e.what()<<endl;
}
f(x+2);
}