From: Mikko Rasa Date: Thu, 17 Jan 2013 11:52:48 +0000 (+0200) Subject: Create a dedicated exception class for vehicle attachment errors X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=9bab44d27a89602565270e71d8684fb3f2fac5be;p=r2c2.git Create a dedicated exception class for vehicle attachment errors --- diff --git a/source/libr2c2/vehicle.cpp b/source/libr2c2/vehicle.cpp index 6b89fa8..cf00c77 100644 --- a/source/libr2c2/vehicle.cpp +++ b/source/libr2c2/vehicle.cpp @@ -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; diff --git a/source/libr2c2/vehicle.h b/source/libr2c2/vehicle.h index f459d32..8990a5b 100644 --- a/source/libr2c2/vehicle.h +++ b/source/libr2c2/vehicle.h @@ -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: