]> git.tdb.fi Git - r2c2.git/commitdiff
Fix remaining exception class names
authorMikko Rasa <tdb@tdb.fi>
Thu, 17 Jan 2013 12:13:08 +0000 (14:13 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 17 Jan 2013 12:22:31 +0000 (14:22 +0200)
33 files changed:
source/3d/catalogue.cpp
source/3d/overlay.cpp
source/3d/path.cpp
source/3d/tracktype.cpp
source/3d/vehicletype.cpp
source/designer/designer.cpp
source/engineer/engineer.cpp
source/engineer/options.cpp
source/engineer/timetabledialog.cpp
source/engineer/trainproperties.cpp
source/libr2c2/articlenumber.cpp
source/libr2c2/block.cpp
source/libr2c2/blockiter.cpp
source/libr2c2/centralstation.cpp
source/libr2c2/controller.cpp
source/libr2c2/driver.cpp
source/libr2c2/intellibox.cpp
source/libr2c2/layout.cpp
source/libr2c2/profile.cpp
source/libr2c2/route.cpp
source/libr2c2/simplecontroller.cpp
source/libr2c2/speedquantizer.cpp
source/libr2c2/timetable.cpp
source/libr2c2/track.cpp
source/libr2c2/trackiter.cpp
source/libr2c2/trackpart.cpp
source/libr2c2/tracktype.cpp
source/libr2c2/train.cpp
source/libr2c2/vehicle.cpp
source/libr2c2/vehicletype.cpp
source/libr2c2/zone.cpp
source/network/server.cpp
source/remote/remote.cpp

index 8d31219eb24dfabc1c718457be7db9fda7c5ac76..7169c60c3272be579162ec093fdbd1c5672a764e 100644 (file)
@@ -94,7 +94,7 @@ FS::Path Catalogue3D::locate_file(const string &name)
        if(FS::exists(path))
                return path;
 
-       throw Exception("Can't locate "+name);
+       throw runtime_error("Can't locate "+name);
 }
 
 template<typename T>
index cf0cd269148878cc45606dcdd6bef8a09a119be2..c10a8db59121c31e35cf75d887a9172cf9f3ff90 100644 (file)
@@ -140,7 +140,7 @@ const GL::Mesh *Overlay3D::get_graphic(const string &name)
                {
                        DataFile::load(*grf, (FS::Path("icons")/(name+".mesh")).str());
                }
-               catch(const Exception &e)
+               catch(const exception &e)
                {
                        IO::print("Error loading overlay graphic '%s': %s\n", name, e.what());
                        delete grf;
index 98ead14774c3ac7904f128945d292fb18291f815..44c54ab35dc8defbce1df8a4535100dacbd5b29d 100644 (file)
@@ -6,6 +6,7 @@
 #include "track.h"
 #include "tracktype.h"
 
+using namespace std;
 using namespace Msp;
 
 namespace R2C2 {
@@ -32,7 +33,7 @@ void Path3D::set_automatic()
 void Path3D::set_path(unsigned p)
 {
        if(!(track.get_track().get_type().get_paths()&(1<<p)))
-               throw InvalidParameterValue("Invalid path");
+               throw invalid_argument("Path3D::set_path");
        automatic = false;
        paths = 1<<p;
 }
@@ -40,7 +41,7 @@ void Path3D::set_path(unsigned p)
 void Path3D::set_mask(unsigned p)
 {
        if(p&~track.get_track().get_type().get_paths())
-               throw InvalidParameterValue("Invalid path mask");
+               throw invalid_argument("Path3D::set_mask");
        automatic = false;
        paths = p;
 }
index cf33d054345f362dc393d20f1ddf09b39a647f9a..243da7fc4830c5279d782dc4d76499ccc2eb5fff 100644 (file)
@@ -177,8 +177,10 @@ void TrackType3D::get_bounds(float angle, Vector &minp, Vector &maxp) const
 
 const GL::Mesh &TrackType3D::get_path_mesh(unsigned p) const
 {
-       if(p>=path_meshes.size() || !path_meshes[p])
-               throw InvalidParameterValue("Invalid path");
+       if(p>=path_meshes.size())
+               throw out_of_range("TrackType3D::get_path_mesh");
+       if(!path_meshes[p])
+               throw invalid_argument("TrackType3D::get_path_mesh");
        return *path_meshes[p];
 }
 
index 9cbfa28f3eac5c891a938c43c0a28e2b21037048..620e6d807a8332d2f02493a0105139b83cf953c2 100644 (file)
@@ -59,30 +59,30 @@ VehicleType3D::~VehicleType3D()
 const GL::Object *VehicleType3D::get_fixed_axle_object(unsigned i) const
 {
        if(i>=axle_objects[0].size())
-               throw InvalidParameterValue("Axle index out of range");
+               throw out_of_range("VehicleType3D::get_fixed_axle_object");
        return axle_objects[0][i];
 }
 
 const GL::Object *VehicleType3D::get_bogie_object(unsigned i) const
 {
        if(i>=bogie_objects.size())
-               throw InvalidParameterValue("Bogie index out of range");
+               throw out_of_range("VehicleType3D::get_bogie_object");
        return bogie_objects[i];
 }
 
 const GL::Object *VehicleType3D::get_bogie_axle_object(unsigned i, unsigned j) const
 {
        if(i>=bogie_objects.size())
-               throw InvalidParameterValue("Bogie index out of range");
+               throw out_of_range("VehicleType3D::get_bogie_axle_object");
        if(j>=axle_objects[i+1].size())
-               throw InvalidParameterValue("Axle index out of range");
+               throw out_of_range("VehicleType3D::get_bogie_axle_object");
        return axle_objects[i+1][j];
 }
 
 const GL::Object *VehicleType3D::get_rod_object(unsigned i) const
 {
        if(i>=rod_objects.size())
-               throw InvalidParameterValue("Rod index out of range");
+               throw out_of_range("VehicleType3D::get_rod_object");
        return rod_objects[i];
 }
 
index 230b46f1ba0df23888a27bd54d7dcd8774d64361..d73ef70ba36833dc40cd485e412487a2dd261d17 100644 (file)
@@ -280,7 +280,7 @@ void Designer::add_selection_to_route()
        {
                cur_route->add_tracks(selection.get_tracks());
        }
-       catch(const Exception &e)
+       catch(const exception &e)
        {
                lbl_status->set_text(e.what());
        }
@@ -319,7 +319,7 @@ void Designer::add_selection_to_zone()
        {
                cur_zone->add_tracks(selection.get_tracks());
        }
-       catch(const Exception &e)
+       catch(const exception &e)
        {
                lbl_status->set_text(e.what());
        }
index dfc677d46410fcf33f3de7f9e0dfd746470e2d07..b9e252301b5adbd1b3d77bc0ec6f068ba85239d9 100644 (file)
@@ -3,7 +3,6 @@
 #include <cstdlib>
 #include <limits>
 #include <signal.h>
-#include <msp/core/except.h>
 #include <msp/fs/stat.h>
 #include <msp/fs/utils.h>
 #include <msp/graphics/display.h>
index 42fa8b6e4c50921433fa3628b61070ab080f19d1..89e1fd109be155a3172aa488afc2619bf89d42fe 100644 (file)
@@ -35,12 +35,12 @@ Options::Options(int argc, char **argv):
                        screen_h = lexical_cast<unsigned>(m[2].str);
                }
                else
-                       throw UsageError("Invalid resolution");
+                       throw usage_error("Invalid resolution");
        }
 
        const vector<string> &args = getopt.get_args();
        if(args.empty())
-               throw UsageError("No layout given");
+               throw usage_error("No layout given");
 
        layout_fn = args[0];
 
index 1d0842a83328ab248fd11eb2a852c9df82297895..8a185cd156f85b7e072deda6b202280c88630f1d 100644 (file)
@@ -63,7 +63,7 @@ void TimetableDialog::on_response(int code)
                        for(vector<Timetable::Row>::const_iterator i=rows.begin(); i!=rows.end(); ++i)
                                timetable.append(*i);
                }
-               catch(const Exception &e)
+               catch(const exception &e)
                {
                        // XXX Need a better way to report errors.  Also, should not let the dialog close.
                        IO::print("%s\n", e.what());
index 867e0a8d32c1e49c02f6cf1b61e59e9936bdf40e..67e096a8ea84b6e1cce858e97fcc831eb24289b8 100644 (file)
@@ -171,5 +171,5 @@ const VehicleType &TrainProperties::get_vehicle_type(unsigned n, bool loco)
                ++i;
        }
 
-       throw InvalidParameterValue("Vehicle type index out of range");
+       throw out_of_range("TrainProperties::get_vehicle_type");
 }
index 1a8d63ac16e483328fd0a2a692c5fd0fba4b6b90..6952ccb9983eda2186ca3ce1edbf927cb3606270 100644 (file)
@@ -20,7 +20,7 @@ ArticleNumber::ArticleNumber(const string &s)
        for(vector<string>::iterator i=sparts.begin(); i!=sparts.end(); ++i)
        {
                if(i->empty())
-                       throw InvalidParameterValue("Malformed article number");
+                       throw invalid_argument("ArticleNumber::ArticleNumber");
 
                unsigned nondigit = i->size();
                for(unsigned j=0; j<i->size(); ++j)
@@ -31,7 +31,7 @@ ArticleNumber::ArticleNumber(const string &s)
                        }
 
                if(!nondigit || nondigit<i->size()-1)
-                       throw InvalidParameterValue("Malformed article number");
+                       throw invalid_argument("ArticleNumber::ArticleNumber");
 
                Part part;
                part.number = lexical_cast<unsigned>(i->substr(0, nondigit));
index ec313d9d415240dab9114a27be838f27111112e4..8bab92c1f87f63159ebda4f221cc0e1535de2d39 100644 (file)
@@ -86,7 +86,7 @@ bool Block::has_track(Track &t) const
 const Block::Endpoint &Block::get_endpoint(unsigned i) const
 {
        if(i>=endpoints.size())
-               throw InvalidParameterValue("Endpoint index out of range");
+               throw out_of_range("Block::get_endpoint");
 
        return endpoints[i];
 }
@@ -103,7 +103,7 @@ int Block::get_endpoint_by_link(Block &other) const
 float Block::get_path_length(unsigned entry, const Route *route) const
 {
        if(entry>=endpoints.size())
-               throw InvalidParameterValue("Endpoint index out of range");
+               throw out_of_range("Block::get_path_length");
 
        TrackIter t_iter(endpoints[entry].track, endpoints[entry].track_ep);
 
@@ -152,7 +152,7 @@ void Block::break_link(Block &other)
 Block *Block::get_link(unsigned epi) const
 {
        if(epi>=endpoints.size())
-               throw InvalidParameterValue("Endpoint index out of range");
+               throw out_of_range("Block::get_link");
        return endpoints[epi].link;
 }
 
index c39f88ed55ca595ac5e67c69d75b995c16ffac80..e662a92ad2020337088d1055d8850c5c0cc93620 100644 (file)
@@ -1,4 +1,3 @@
-#include <msp/core/except.h>
 #include "block.h"
 #include "blockiter.h"
 #include "route.h"
@@ -19,7 +18,7 @@ BlockIter::BlockIter(Block *b, unsigned e):
        _entry(b ? e : 0)
 {
        if(_block && _entry>_block->get_endpoints().size())
-               throw InvalidParameterValue("Endpoint index not valid for block");
+               throw out_of_range("BlockIter::BlockIter");
 }
 
 TrackIter BlockIter::track_iter() const
@@ -34,7 +33,7 @@ TrackIter BlockIter::track_iter() const
 const Block::Endpoint &BlockIter::endpoint() const
 {
        if(!_block)
-               throw InvalidState("BlockIter is null");
+               throw logic_error("null block");
 
        return _block->get_endpoint(_entry);
 }
@@ -47,7 +46,7 @@ int BlockIter::get_exit(const Route *route) const
        while(t_iter)
        {
                if(!_block->has_track(*t_iter))
-                       throw LogicError("Block traversal strayed out of the block");
+                       throw logic_error("internal error (block traversal escaped the block)");
 
                unsigned path = (route ? route->get_path(*t_iter) : t_iter->get_active_path());
                TrackIter t_exit = t_iter.reverse(path);
@@ -105,7 +104,7 @@ BlockIter BlockIter::flip() const
 Block &BlockIter::operator*() const
 {
        if(!_block)
-               throw InvalidState("BlockIter is null");
+               throw logic_error("null block");
 
        return *_block;
 }
index a41a494c440243c266d10379bd40236ea06fb03c..979749e401a446469b506638a08ac716cc639978 100644 (file)
@@ -613,7 +613,7 @@ CentralStation::Protocol CentralStation::map_protocol(const string &name) const
        else if(name=="MFX")
                return MFX;
        else
-               throw InvalidParameterValue("Unknown protocol");
+               throw invalid_argument("CentralStation::map_protocol");
 }
 
 template<typename T>
index 660363d6c53f12beee31ab36315c35cc7282c762..ebec9903da0f450fd0ef4a91bfbc9ddecf2b7d0b 100644 (file)
@@ -1,9 +1,7 @@
 #include <cmath>
-#include <msp/core/except.h>
 #include "controller.h"
 
 using namespace std;
-using namespace Msp;
 
 namespace R2C2 {
 
@@ -37,7 +35,7 @@ Controller::Control Controller::Control::binary(const string &n)
 Controller::Control Controller::Control::discrete(const string &n, float m, float x, float s)
 {
        if(x<m)
-               throw InvalidParameterValue("Max value must be greater than min value");
+               throw invalid_argument("Controller::Control::discrete");
 
        Controller::Control tc;
        tc.name = n;
@@ -53,7 +51,7 @@ Controller::Control Controller::Control::discrete(const string &n, float m, floa
 Controller::Control Controller::Control::continuous(const string &n, float m, float x)
 {
        if(x<m)
-               throw InvalidParameterValue("Max value must be greater than min value");
+               throw invalid_argument("Controller::Control::continuous");
 
        Controller::Control tc;
        tc.name = n;
index 22b241c61a5c8bf51faaa5101c8ed738d6483ddf..46548e82590ed3e11962184ded5f14f8b86edf25 100644 (file)
@@ -1,4 +1,3 @@
-#include <msp/core/except.h>
 #include "centralstation.h"
 #include "driver.h"
 #include "dummy.h"
@@ -24,7 +23,7 @@ Driver *Driver::create(const string &str)
        else if(type=="dummy")
                return new Dummy;
 
-       throw Msp::InvalidParameterValue("Unknown driver");
+       throw invalid_argument("Driver::create");
 }
 
 } // namespace R2C2
index 09e4792e36a0d5837ef12b14a48f7ce9fd04fbac..82623e1760891a4b4e0e9d55a3094eddb5bc1f5e 100644 (file)
@@ -42,7 +42,7 @@ Intellibox::Intellibox(const string &dev):
        }
 
        if(!ok)
-               throw Exception("IB not detected");
+               throw runtime_error("IB not detected");
 
        if(p50)
                serial.write("xZzA1\r", 6);
@@ -354,7 +354,7 @@ Intellibox::Protocol Intellibox::map_protocol(const string &name) const
        else if(name=="MM-27")
                return MM_27;
        else
-               throw InvalidParameterValue("Unknown protocol");
+               throw invalid_argument("Intellibox::map_protocol");
 }
 
 void Intellibox::command(Command cmd)
index 821482ae1da813c76cfeb32e64b2747dcac548fa..dfa56df02a93ae4ce6b0dffaec99b003a0f2b05b 100644 (file)
@@ -57,7 +57,7 @@ Layout::~Layout()
 Driver &Layout::get_driver() const
 {
        if(!driver)
-               throw InvalidState("No driver");
+               throw logic_error("!driver");
        return *driver;
 }
 
index 2741cac2958c3a848ba39b48aa7ba304b72289da..a9951b2aebc5ab88139edd69c1447b97f7333064 100644 (file)
@@ -55,7 +55,7 @@ void Profile::append_vertex(const Vector &p, bool smooth)
 const Profile::Vertex &Profile::get_vertex(unsigned i) const
 {
        if(i>=vertices.size())
-               throw InvalidParameterValue("Index out of range");
+               throw out_of_range("Profile::get_vertex");
        return vertices[i];
 }
 
index aabe8807b71cd4b7d92927ca6427edce21f804d1..820ce1e32dad1536cce73ec313edfe70de9780f2 100644 (file)
@@ -169,10 +169,10 @@ void Route::set_temporary(bool t)
 void Route::set_turnout(unsigned addr, unsigned path)
 {
        if(!addr)
-               throw InvalidParameterValue("Invalid turnout address");
+               throw invalid_argument("Route::set_turnout");
        int &state = get_item(turnouts, addr);
        if(state>=0 && path!=static_cast<unsigned>(state))
-               throw InvalidState("Setting conflicts with route");
+               throw logic_error("route conflict");
        state = path;
 }
 
index d88ade005929309e38d15f04714e7fa08278cad0..d04acab4a045502d6326927429c625fd568a2d29 100644 (file)
@@ -1,4 +1,3 @@
-#include <msp/core/except.h>
 #include <msp/core/maputils.h>
 #include <msp/time/units.h>
 #include "simplecontroller.h"
@@ -37,7 +36,7 @@ void SimpleController::set_control(const string &name, float v)
        else if(name==reverse.name)
        {
                if(target_speed.value || speed)
-                       throw InvalidState("Must be stopped to change reverse");
+                       throw logic_error("Must be stopped to change reverse");
                reverse.set(v);
                signal_control_changed.emit(reverse);
        }
index 1098d437c38e76caf7ecb6f1afdd335ae5aaf2e5..9fa127cb3125fcce5868416d71535558d98195e8 100644 (file)
@@ -10,13 +10,13 @@ SpeedQuantizer::SpeedQuantizer(unsigned n):
        weight_limit(10)
 {
        if(n<1)
-               throw InvalidParameterValue("Must have at leats one speed step");
+               throw invalid_argument("SpeedQuantizer::SpeedQuantizer");
 }
 
 void SpeedQuantizer::learn(unsigned i, float s, float w)
 {
        if(i>=steps.size())
-               throw InvalidParameterValue("Speed step index out of range");
+               throw out_of_range("SpeedQuantizer::learn");
        steps[i].add(s, w);
 }
 
index 82c5411378c6e5c0f67277f2e328f3ad56e450f0..9fd44df6d80a480b6d9eb95e9a3cec1cc82e6550 100644 (file)
@@ -55,7 +55,7 @@ void Timetable::append(const Row &row)
 void Timetable::insert(unsigned i, const Row &row)
 {
        if(i>rows.size())
-               throw InvalidParameterValue("Insert position out of range");
+               throw out_of_range("Timetable::insert");
 
        rows.insert(rows.begin()+i, row);
        if(i<=current_row)
@@ -65,7 +65,7 @@ void Timetable::insert(unsigned i, const Row &row)
 const Timetable::Row &Timetable::get_row(unsigned i) const
 {
        if(i>=rows.size())
-               throw InvalidParameterValue("Row index out of range");
+               throw out_of_range("Timetable::get_row");
        return rows[i];
 }
 
@@ -187,7 +187,7 @@ Zone &Timetable::get_zone(const string &name)
 {
        string::size_type space = name.rfind(' ');
        if(space==string::npos || space==0)
-               throw InvalidParameterValue("Invalid zone name");
+               throw invalid_argument("Timetable::get_zone");
        unsigned number = lexical_cast<unsigned>(name.substr(space+1));
        return train.get_layout().get_zone(name.substr(0, space), number);
 }
@@ -263,7 +263,7 @@ template<typename T>
 const T &Timetable::Row::get_param(unsigned i) const
 {
        if(i>=params.size())
-               throw InvalidParameterValue("Parameter index out of range");
+               throw out_of_range("Timetable::Row::get_param");
        return params[i].value<T>();
 }
 
@@ -402,7 +402,7 @@ Timetable::Row Timetable::Row::parse(const string &s)
                return Row(ROUTE, s.substr(10));
        }
 
-       throw InvalidParameterValue("Invalid row");
+       throw invalid_argument("Timetable::Row::parse");
 }
 
 
index cf496c41ddae554b98da55d62e67bc2b3e0179b4..2cb95186e6f32237a61b16e092a5eac279a7ba13 100644 (file)
@@ -43,9 +43,9 @@ Track::~Track()
 void Track::set_block(Block *b)
 {
        if(b && !b->has_track(*this))
-               throw InvalidParameterValue("Track is not in the Block");
+               throw logic_error("track not in block");
        if(!b && block && block->has_track(*this))
-               throw InvalidState("Track is still in a Block");
+               throw logic_error("track still in block");
 
        block = b;
 }
@@ -53,7 +53,7 @@ void Track::set_block(Block *b)
 Block &Track::get_block() const
 {
        if(!block)
-               throw InvalidState("No Block");
+               throw logic_error("!block");
 
        return *block;
 }
@@ -116,7 +116,7 @@ void Track::check_slope()
 void Track::set_turnout_id(unsigned i)
 {
        if(!type.is_turnout())
-               throw InvalidState("Not a turnout");
+               throw logic_error("not a turnout");
 
        turnout_id = i;
        layout.create_blocks(*this);
@@ -128,7 +128,7 @@ void Track::set_turnout_id(unsigned i)
 void Track::set_sensor_id(unsigned i)
 {
        if(type.is_turnout())
-               throw InvalidState("Can't set sensor on a turnout");
+               throw logic_error("is a turnout");
 
        sensor_id = i;
        layout.create_blocks(*this);
@@ -139,9 +139,9 @@ void Track::set_sensor_id(unsigned i)
 void Track::set_active_path(unsigned p)
 {
        if(!turnout_id)
-               throw InvalidState("Not a turnout");
+               throw logic_error("not a turnout");
        if(!(type.get_paths()&(1<<p)))
-               throw InvalidParameterValue("Invalid path");
+               throw invalid_argument("Track::set_active_path");
 
        layout.get_driver().set_turnout(turnout_id, p);
 }
@@ -159,7 +159,7 @@ Vector Track::get_endpoint_position(unsigned epi) const
 {
        const vector<TrackType::Endpoint> &eps = type.get_endpoints();
        if(epi>=eps.size())
-               throw InvalidParameterValue("TrackType::Endpoint index out of range");
+               throw out_of_range("Track::get_endpoint_position");
 
        const TrackType::Endpoint &ep = eps[epi];
 
@@ -176,7 +176,7 @@ float Track::get_endpoint_direction(unsigned epi) const
 {
        const vector<TrackType::Endpoint> &eps = type.get_endpoints();
        if(epi>=eps.size())
-               throw InvalidParameterValue("TrackType::Endpoint index out of range");
+               throw out_of_range("Track::get_endpoint_direction");
 
        const TrackType::Endpoint &ep = eps[epi];
 
@@ -289,7 +289,7 @@ void Track::break_links()
 Track *Track::get_link(unsigned i) const
 {
        if(i>links.size())
-               throw InvalidParameterValue("Link index out of range");
+               throw out_of_range("Track::get_link");
 
        return links[i];
 }
index c5663f29dfe23f26b50e865264921ce4073d7db7..c636d27c84cef8a30d6c700bb6fd454c9d49c9e0 100644 (file)
@@ -1,5 +1,4 @@
 #include <algorithm>
-#include <msp/core/except.h>
 #include "track.h"
 #include "trackiter.h"
 #include "tracktype.h"
@@ -19,13 +18,13 @@ TrackIter::TrackIter(Track *t, unsigned e):
        _entry(t ? e : 0)
 {
        if(_track && _entry>_track->get_type().get_endpoints().size())
-               throw InvalidParameterValue("Endpoint index not valid for track");
+               throw out_of_range("TrackIter::TrackIter");
 }
 
 const TrackType::Endpoint &TrackIter::endpoint() const
 {
        if(!_track)
-               throw InvalidState("TrackIter is null");
+               throw logic_error("null track");
 
        return _track->get_type().get_endpoint(_entry);
 }
@@ -101,7 +100,7 @@ TrackIter TrackIter::flip() const
 Track &TrackIter::operator*() const
 {
        if(!_track)
-               throw InvalidState("TrackIter is null");
+               throw logic_error("null track");
 
        return *_track;
 }
index 79e183b5a9ce54ad3892f488270882bce4511e7f..2b3809dd7809d1b31bdea92ca5ca6e73a83430d0 100644 (file)
@@ -81,7 +81,7 @@ void TrackPart::check_link(TrackPart &other)
 TrackPart *TrackPart::get_link(unsigned i) const
 {
        if(i>=2)
-               throw InvalidParameterValue("Index out of range");
+               throw out_of_range("TrackPart::get_link");
        return links[i];
 }
 
index b6971ca92175badf5cbddbcf772c9a785bc04140..c7a6aef7ba70fa85bac12a2ac2c1ff1738cc6a6e 100644 (file)
@@ -55,7 +55,7 @@ bool TrackType::is_dead_end() const
 const TrackType::Endpoint &TrackType::get_endpoint(unsigned i) const
 {
        if(i>=endpoints.size())
-               throw InvalidParameterValue("Endpoint index out of range");
+               throw out_of_range("TrackType::get_endpoint");
 
        return endpoints[i];
 }
@@ -63,7 +63,7 @@ const TrackType::Endpoint &TrackType::get_endpoint(unsigned i) const
 TrackPoint TrackType::get_point(unsigned epi, unsigned path, float d) const
 {
        if(epi>=endpoints.size())
-               throw InvalidParameterValue("Endpoint index out of range");
+               throw out_of_range("TrackType::get_point");
 
        const TrackPart *part = 0;
        unsigned part_ep = 0;
@@ -87,7 +87,7 @@ TrackPoint TrackType::get_point(unsigned epi, unsigned path, float d) const
        }
 
        if(!part)
-               throw Exception("Internal error (endpoint does not match any part)");
+               throw logic_error("internal error (endpoint does not match any part)");
 
        while(1)
        {
@@ -106,7 +106,7 @@ TrackPoint TrackType::get_point(unsigned epi, unsigned path, float d) const
                        d -= plen;
                        TrackPart *next = part->get_link(1-part_ep);
                        if(!next)
-                               throw InvalidParameterValue("Distance out of range");
+                               throw invalid_argument("TrackType::get_point");
                        part_ep = (next->get_link(0)==part ? 0 : 1);
                        part = next;
                }
index 5f1b46bd950f625fb04581565d7bc849c4a224ad..099e7611c3fbe7c63c1da2a6d432acc8614228a0 100644 (file)
@@ -64,7 +64,7 @@ Train::Train(Layout &l, const VehicleType &t, unsigned a, const string &p):
        overshoot_dist(false)
 {
        if(!loco_type.is_locomotive())
-               throw InvalidParameterValue("Initial vehicle must be a locomotive");
+               throw invalid_argument("Train::Train");
 
        unsigned speed_steps = layout.get_driver().get_protocol_speed_steps(protocol);
        if(speed_steps)
@@ -126,9 +126,9 @@ void Train::add_vehicle(const VehicleType &vt)
 void Train::remove_vehicle(unsigned i)
 {
        if(i>=vehicles.size())
-               throw InvalidParameterValue("Vehicle index out of range");
+               throw out_of_range("Train::remove_vehicle");
        if(i==0)
-               throw InvalidParameterValue("Can't remove the locomotive");
+               throw logic_error("can't remove locomotive");
        delete vehicles[i];
        vehicles.erase(vehicles.begin()+i);
        if(i<vehicles.size())
@@ -143,14 +143,14 @@ unsigned Train::get_n_vehicles() const
 Vehicle &Train::get_vehicle(unsigned i)
 {
        if(i>=vehicles.size())
-               throw InvalidParameterValue("Vehicle index out of range");
+               throw out_of_range("Train::get_vehicle");
        return *vehicles[i];
 }
 
 const Vehicle &Train::get_vehicle(unsigned i) const
 {
        if(i>=vehicles.size())
-               throw InvalidParameterValue("Vehicle index out of range");
+               throw out_of_range("Train::get_vehicle");
        return *vehicles[i];
 }
 
@@ -164,7 +164,7 @@ void Train::set_active(bool a)
        if(a==active)
                return;
        if(!a && controller->get_speed())
-               throw InvalidState("Can't deactivate while moving");
+               throw logic_error("moving");
 
        active = a;
        if(active)
@@ -179,7 +179,7 @@ void Train::set_active(bool a)
 void Train::set_function(unsigned func, bool state)
 {
        if(!loco_type.get_functions().count(func))
-               throw InvalidParameterValue("Invalid function");
+               throw invalid_argument("Train::set_function");
        layout.get_driver().set_loco_function(address, func, state);
 }
 
@@ -321,7 +321,7 @@ bool Train::go_to(const Zone &to)
 bool Train::divert(Track &from)
 {
        if(!from.get_turnout_id())
-               throw InvalidParameterValue("Can't divert from a non-turnout");
+               throw invalid_argument("Train::divert");
        if(routes.empty())
                return false;
 
@@ -395,7 +395,7 @@ bool Train::divert(Track &from)
                if(end!=routes.end())
                        break;
                else if(!diversion->has_track(*track))
-                       throw LogicError("Pathfinder returned a bad route");
+                       throw logic_error("bad diversion");
 
                track = track.next(diversion->get_path(*track));
        }
@@ -423,7 +423,7 @@ const Route *Train::get_route() const
 void Train::place(Block &block, unsigned entry)
 {
        if(controller->get_speed())
-               throw InvalidState("Must be stopped before placing");
+               throw logic_error("moving");
 
        release_blocks();
 
@@ -449,7 +449,7 @@ void Train::place(Block &block, unsigned entry)
 void Train::unplace()
 {
        if(controller->get_speed())
-               throw InvalidState("Must be stopped before unplacing");
+               throw logic_error("moving");
 
        release_blocks();
 
@@ -977,7 +977,7 @@ void Train::reserve_more()
                        Train *other_train = block->get_train();
                        int other_entry = other_train->get_entry_to_block(*block);
                        if(other_entry<0)
-                               throw LogicError("Block reservation inconsistency");
+                               throw logic_error("block reservation inconsistency");
 
                        unsigned exit = block.reverse().entry();
                        unsigned other_exit = BlockIter(block.block(), other_entry).reverse().entry();
index cf00c7706e3e991a9acc53d607f7c56798bb5595..1699fd8eeef1cf0b89618cb806d3c6623aabc07b 100644 (file)
@@ -121,30 +121,30 @@ void Vehicle::advance(float d)
 const Vehicle::Axle &Vehicle::get_fixed_axle(unsigned i) const
 {
        if(i>=axles.size())
-               throw InvalidParameterValue("Axle index out of range");
+               throw out_of_range("Vehicle::get_fixed_axle");
        return axles[i];
 }
 
 const Vehicle::Bogie &Vehicle::get_bogie(unsigned i) const
 {
        if(i>=bogies.size())
-               throw InvalidParameterValue("Bogie index out of range");
+               throw out_of_range("Vehicle::get_bogie");
        return bogies[i];
 }
 
 const Vehicle::Axle &Vehicle::get_bogie_axle(unsigned i, unsigned j) const
 {
        if(i>=bogies.size())
-               throw InvalidParameterValue("Bogie index out of range");
+               throw out_of_range("Vehicle::get_bogie_axle");
        if(j>=bogies[i].axles.size())
-               throw InvalidParameterValue("Axle index out of range");
+               throw out_of_range("Vehicle::get_bogie_axle");
        return bogies[i].axles[j];
 }
 
 const Vehicle::Rod &Vehicle::get_rod(unsigned i) const
 {
        if(i>=rods.size())
-               throw InvalidParameterValue("Rod index out of range");
+               throw out_of_range("Vehicle::get_rod");
        return rods[i];
 }
 
index 9f8814652770448aa1ae1dc84f5b4d542f4e167a..720b922a183a911bef72f9b916243a0bc1d9a63e 100644 (file)
@@ -1,4 +1,5 @@
 #include <msp/core/maputils.h>
+#include <msp/strings/format.h>
 #include "vehicletype.h"
 
 using namespace std;
@@ -25,30 +26,30 @@ unsigned VehicleType::get_max_function() const
 const VehicleType::Axle &VehicleType::get_fixed_axle(unsigned i) const
 {
        if(i>=axles.size())
-               throw InvalidParameterValue("Axle index out of range");
+               throw out_of_range("VehicleType::get_fixed_axle");
        return axles[i];
 }
 
 const VehicleType::Bogie &VehicleType::get_bogie(unsigned i) const
 {
        if(i>=bogies.size())
-               throw InvalidParameterValue("Axle index out of range");
+               throw out_of_range("VehicleType::get_bogie");
        return bogies[i];
 }
 
 const VehicleType::Axle &VehicleType::get_bogie_axle(unsigned i, unsigned j) const
 {
        if(i>=bogies.size())
-               throw InvalidParameterValue("Axle index out of range");
+               throw out_of_range("VehicleType::get_bogie_axle");
        if(j>=bogies[i].axles.size())
-               throw InvalidParameterValue("Axle index out of range");
+               throw out_of_range("VehicleType::get_bogie_axle");
        return bogies[i].axles[j];
 }
 
 const VehicleType::Rod &VehicleType::get_rod(unsigned i) const
 {
        if(i>=rods.size())
-               throw InvalidParameterValue("Rod index out of range");
+               throw out_of_range("VehicleType::get_rod");
        return rods[i];
 }
 
@@ -274,7 +275,7 @@ void operator>>(const LexicalConverter &c, VehicleType::Rod::Limit &l)
        else if(s=="SLIDE_X")
                l = VehicleType::Rod::SLIDE_X;
        else
-               throw LexicalError("Invalid value for Rod::Limit");
+               throw lexical_error(format("conversion of '%s' to Rod::Limit", s));
 }
 
 } // namespace R2C2
index 28b178afff15107c470cacf16b2dc9cfb674e63e..eddcfc9386749fb4ca6ece84be58a361d17a4124 100644 (file)
@@ -46,7 +46,7 @@ string Zone::get_name() const
 void Zone::add_track(Track &track)
 {
        if(!is_valid(track))
-               throw InvalidParameterValue("Can't add track to zone");
+               throw logic_error("unconnected");
 
        tracks.insert(&track);
 }
@@ -70,7 +70,7 @@ bool Zone::add_tracks(const TrackSet &trks)
                if(!ok)
                {
                        if(first)
-                               throw InvalidParameterValue("Cound not add any tracks to zone");
+                               throw logic_error("unconnected");
                        return pending.empty();
                }
 
index c9a56e39b243d7673d15c80259d4410658aabe8f..c0a69463622d17d5f8b65fb55fd886692994ee36 100644 (file)
@@ -230,7 +230,7 @@ void Server::Connection::receive(const TrainControlPacket &pkt)
                Train &train = server.layout.get_train(pkt.address);
                train.set_control(pkt.control, pkt.value);
        }
-       catch(const Exception &e)
+       catch(const exception &e)
        {
                error(e.what());
        }
@@ -245,7 +245,7 @@ void Server::Connection::receive(const TrainFunctionPacket &pkt)
                        if(((pkt.functions^train.get_functions())>>i)&1)
                                train.set_function(i, (pkt.functions>>i)&1);
        }
-       catch(const Exception &e)
+       catch(const exception &e)
        {
                error(e.what());
        }
@@ -264,7 +264,7 @@ void Server::Connection::receive(const TrainRoutePacket &pkt)
                        train.set_route(&route);
                }
        }
-       catch(const Exception &e)
+       catch(const exception &e)
        {
                error(e.what());
        }
index 07395da99887ab739df25210cd85ec511404618a..b60d11ffe1920ae654f96f5cece9e62c61e7d0ea 100644 (file)
@@ -1,5 +1,6 @@
 #include <gtkmm/scrolledwindow.h>
 #include <gtkmm/separator.h>
+#include <msp/core/getopt.h>
 #include <msp/net/resolve.h>
 #include <msp/time/units.h>
 #include "mainpanel.h"
@@ -16,7 +17,7 @@ Remote::Remote(int argc, char **argv):
        gtk(argc, argv)
 {
        if(argc<2)
-               throw UsageError("No address given");
+               throw usage_error("No address given");
 
        DataFile::load(catalogue, "locos.dat");