]> git.tdb.fi Git - r2c2.git/commitdiff
Create a dedicated exception class for vehicle attachment errors
authorMikko Rasa <tdb@tdb.fi>
Thu, 17 Jan 2013 11:52:48 +0000 (13:52 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 17 Jan 2013 11:52:48 +0000 (13:52 +0200)
source/libr2c2/vehicle.cpp
source/libr2c2/vehicle.h

index 6b89fa8743b604036ccab17c7a42a48e94e8c208..cf00c7706e3e991a9acc53d607f7c56798bb5595 100644 (file)
@@ -41,7 +41,7 @@ Vehicle::~Vehicle()
 void Vehicle::attach_back(Vehicle &veh)
 {
        if(next || veh.prev)
-               throw InvalidState("Already attached");
+               throw attachment_error("already attached");
 
        next = &veh;
        veh.prev = this;
@@ -53,7 +53,7 @@ void Vehicle::attach_back(Vehicle &veh)
 void Vehicle::attach_front(Vehicle &veh)
 {
        if(prev || veh.next)
-               throw InvalidState("Already attached");
+               throw attachment_error("already attached");
 
        prev = &veh;
        veh.next = this;
@@ -65,7 +65,7 @@ void Vehicle::attach_front(Vehicle &veh)
 void Vehicle::detach_back()
 {
        if(!next)
-               throw InvalidState("Not attached");
+               throw attachment_error("not attached");
 
        next->prev = 0;
        next = 0;
@@ -74,7 +74,7 @@ void Vehicle::detach_back()
 void Vehicle::detach_front()
 {
        if(!prev)
-               throw InvalidState("Not attached");
+               throw attachment_error("not attached");
 
        prev->next = 0;
        prev = 0;
index f459d32a36880ba4315b6e72962cc44c0b52d434..8990a5b538d68c0f144b2404db636229ec6f9f00 100644 (file)
@@ -9,6 +9,14 @@ namespace R2C2 {
 class Layout;
 class Track;
 
+class attachment_error: public std::logic_error
+{
+public:
+       attachment_error(const std::string &w): std::logic_error(w) { }
+       virtual ~attachment_error() throw() { }
+};
+
+
 class Vehicle
 {
 public: