#include	<stdexcept>
#include	<iostream>

using std::cout;		using std::endl;
using std::domain_error;	using std::invalid_argument;
using std::logic_error;		using std::exception;
using std::runtime_error;	using std::out_of_range;
using std::range_error;

int
f()
{
	throw range_error("out of range!");
}

int
main()
{
	try {
		f();
	} catch (const invalid_argument &e) {
		cout << "invalid_argument " << e.what() << endl;
	} catch (const domain_error &e) {
		cout << "domain_error " << e.what() << endl;
	} catch (const logic_error &e) {
		cout << "logic_error " << e.what() << endl;
	} catch (const runtime_error &e) {
                // This catch clause will be used since 'range_error'
		// is a form of 'runtime_error'.
		cout << "runtime_error " << e.what() << endl;
	} catch (const exception &e) {
		// If we didn't have the previous catch clause, then
		// this one would have been used since 'range_error'
		// is a form of 'runtime_error', which, in turn
		// is a form of 'exception'.
		cout << "exception " << e.what() << endl;
	}
}
