#include<iostream>
#include<stdexcept>
#include<string>
using namespace std;
class MyRangeError : public range_error
{
	string msg;
public:
	MyRangeError(const string& m=""): range_error(m),msg(m){};
};
class MyRuntimeError : public runtime_error
{
	string msg;
public:
	MyRuntimeError(const string& m=""): runtime_error(m),msg(m){};
};
class MyLengthError : public length_error
{
	string msg;
public:
	MyLengthError(const string& m=""): length_error(m),msg(m){};
};

void fun(int i)
{
	switch(i)
	{
	  case 0: throw MyRangeError( "a range error");
	  case 1: throw MyRuntimeError("a runtime error");
	  case 2: throw MyLengthError("a length error");
	}

}
void main()
{
	for(int i=0;i!=3;++i)
	{
		try{
		   fun(i);
		}
		catch(MyRangeError& range)
		{
			cout<<range.what()<<endl;
		}
		catch(MyRuntimeError& runtime)
		{
			cout<<runtime.what()<<endl;
		}
		catch(MyLengthError& length)
		{
			cout<<length.what()<<endl;
		}
	}

}