#include <iostream.h>
#define MAXX 80
#define MAXY 25
class Point
{
public:
class xZero {};
class xOutOfScreenBounds {};
Point(unsigned __x, unsigned __y)
{
x = __x;
y = __y;
}
unsigned GetX()
{
return x;
}
unsigned GetY()
{
return y;
}
void SetX(unsigned __x)
{
if(__x > 0)
if(__x < = MAXX)
x = __x;
else
throw xOutOfScreenBounds();
else
throw xZero();
}
void SetY(unsigned __y)
{
if(__y > 0)
if(__y < = MAXY)
y = __y;
else
throw xOutOfScreenBounds();
else
throw xZero();
}
protected:
int x, y;
};
main()
{
Point p(1, 1);
try
{
p.SetX(5);
cout << "p.x successfully set to " << p.GetX() << "." << endl;
p.SetX(100);
}
catch(Point::xZero)
{
cout << "Zero value!\n";
}
catch(Point::xOutOfScreenBounds)
{
cout << "Out of screen bounds!\n";
}
catch(...)
{
cout << Unknown exception!\n";
}
}