From 621c5c938d70ba0d155e0eda91a708db0a52c0dc Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 17 Jan 2013 14:13:08 +0200 Subject: [PATCH] Fix remaining exception class names --- source/3d/catalogue.cpp | 2 +- source/3d/overlay.cpp | 2 +- source/3d/path.cpp | 5 +++-- source/3d/tracktype.cpp | 6 ++++-- source/3d/vehicletype.cpp | 10 +++++----- source/designer/designer.cpp | 4 ++-- source/engineer/engineer.cpp | 1 - source/engineer/options.cpp | 4 ++-- source/engineer/timetabledialog.cpp | 2 +- source/engineer/trainproperties.cpp | 2 +- source/libr2c2/articlenumber.cpp | 4 ++-- source/libr2c2/block.cpp | 6 +++--- source/libr2c2/blockiter.cpp | 9 ++++----- source/libr2c2/centralstation.cpp | 2 +- source/libr2c2/controller.cpp | 6 ++---- source/libr2c2/driver.cpp | 3 +-- source/libr2c2/intellibox.cpp | 4 ++-- source/libr2c2/layout.cpp | 2 +- source/libr2c2/profile.cpp | 2 +- source/libr2c2/route.cpp | 4 ++-- source/libr2c2/simplecontroller.cpp | 3 +-- source/libr2c2/speedquantizer.cpp | 4 ++-- source/libr2c2/timetable.cpp | 10 +++++----- source/libr2c2/track.cpp | 20 ++++++++++---------- source/libr2c2/trackiter.cpp | 7 +++---- source/libr2c2/trackpart.cpp | 2 +- source/libr2c2/tracktype.cpp | 8 ++++---- source/libr2c2/train.cpp | 24 ++++++++++++------------ source/libr2c2/vehicle.cpp | 10 +++++----- source/libr2c2/vehicletype.cpp | 13 +++++++------ source/libr2c2/zone.cpp | 4 ++-- source/network/server.cpp | 6 +++--- source/remote/remote.cpp | 3 ++- 33 files changed, 96 insertions(+), 98 deletions(-) diff --git a/source/3d/catalogue.cpp b/source/3d/catalogue.cpp index 8d31219..7169c60 100644 --- a/source/3d/catalogue.cpp +++ b/source/3d/catalogue.cpp @@ -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 diff --git a/source/3d/overlay.cpp b/source/3d/overlay.cpp index cf0cd26..c10a8db 100644 --- a/source/3d/overlay.cpp +++ b/source/3d/overlay.cpp @@ -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; diff --git a/source/3d/path.cpp b/source/3d/path.cpp index 98ead14..44c54ab 100644 --- a/source/3d/path.cpp +++ b/source/3d/path.cpp @@ -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<=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]; } diff --git a/source/3d/vehicletype.cpp b/source/3d/vehicletype.cpp index 9cbfa28..620e6d8 100644 --- a/source/3d/vehicletype.cpp +++ b/source/3d/vehicletype.cpp @@ -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]; } diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index 230b46f..d73ef70 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -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()); } diff --git a/source/engineer/engineer.cpp b/source/engineer/engineer.cpp index dfc677d..b9e2523 100644 --- a/source/engineer/engineer.cpp +++ b/source/engineer/engineer.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include diff --git a/source/engineer/options.cpp b/source/engineer/options.cpp index 42fa8b6..89e1fd1 100644 --- a/source/engineer/options.cpp +++ b/source/engineer/options.cpp @@ -35,12 +35,12 @@ Options::Options(int argc, char **argv): screen_h = lexical_cast(m[2].str); } else - throw UsageError("Invalid resolution"); + throw usage_error("Invalid resolution"); } const vector &args = getopt.get_args(); if(args.empty()) - throw UsageError("No layout given"); + throw usage_error("No layout given"); layout_fn = args[0]; diff --git a/source/engineer/timetabledialog.cpp b/source/engineer/timetabledialog.cpp index 1d0842a..8a185cd 100644 --- a/source/engineer/timetabledialog.cpp +++ b/source/engineer/timetabledialog.cpp @@ -63,7 +63,7 @@ void TimetableDialog::on_response(int code) for(vector::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()); diff --git a/source/engineer/trainproperties.cpp b/source/engineer/trainproperties.cpp index 867e0a8..67e096a 100644 --- a/source/engineer/trainproperties.cpp +++ b/source/engineer/trainproperties.cpp @@ -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"); } diff --git a/source/libr2c2/articlenumber.cpp b/source/libr2c2/articlenumber.cpp index 1a8d63a..6952ccb 100644 --- a/source/libr2c2/articlenumber.cpp +++ b/source/libr2c2/articlenumber.cpp @@ -20,7 +20,7 @@ ArticleNumber::ArticleNumber(const string &s) for(vector::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; jsize(); ++j) @@ -31,7 +31,7 @@ ArticleNumber::ArticleNumber(const string &s) } if(!nondigit || nondigitsize()-1) - throw InvalidParameterValue("Malformed article number"); + throw invalid_argument("ArticleNumber::ArticleNumber"); Part part; part.number = lexical_cast(i->substr(0, nondigit)); diff --git a/source/libr2c2/block.cpp b/source/libr2c2/block.cpp index ec313d9..8bab92c 100644 --- a/source/libr2c2/block.cpp +++ b/source/libr2c2/block.cpp @@ -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; } diff --git a/source/libr2c2/blockiter.cpp b/source/libr2c2/blockiter.cpp index c39f88e..e662a92 100644 --- a/source/libr2c2/blockiter.cpp +++ b/source/libr2c2/blockiter.cpp @@ -1,4 +1,3 @@ -#include #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; } diff --git a/source/libr2c2/centralstation.cpp b/source/libr2c2/centralstation.cpp index a41a494..979749e 100644 --- a/source/libr2c2/centralstation.cpp +++ b/source/libr2c2/centralstation.cpp @@ -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 diff --git a/source/libr2c2/controller.cpp b/source/libr2c2/controller.cpp index 660363d..ebec990 100644 --- a/source/libr2c2/controller.cpp +++ b/source/libr2c2/controller.cpp @@ -1,9 +1,7 @@ #include -#include #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 #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 diff --git a/source/libr2c2/intellibox.cpp b/source/libr2c2/intellibox.cpp index 09e4792..82623e1 100644 --- a/source/libr2c2/intellibox.cpp +++ b/source/libr2c2/intellibox.cpp @@ -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) diff --git a/source/libr2c2/layout.cpp b/source/libr2c2/layout.cpp index 821482a..dfa56df 100644 --- a/source/libr2c2/layout.cpp +++ b/source/libr2c2/layout.cpp @@ -57,7 +57,7 @@ Layout::~Layout() Driver &Layout::get_driver() const { if(!driver) - throw InvalidState("No driver"); + throw logic_error("!driver"); return *driver; } diff --git a/source/libr2c2/profile.cpp b/source/libr2c2/profile.cpp index 2741cac..a9951b2 100644 --- a/source/libr2c2/profile.cpp +++ b/source/libr2c2/profile.cpp @@ -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]; } diff --git a/source/libr2c2/route.cpp b/source/libr2c2/route.cpp index aabe880..820ce1e 100644 --- a/source/libr2c2/route.cpp +++ b/source/libr2c2/route.cpp @@ -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(state)) - throw InvalidState("Setting conflicts with route"); + throw logic_error("route conflict"); state = path; } diff --git a/source/libr2c2/simplecontroller.cpp b/source/libr2c2/simplecontroller.cpp index d88ade0..d04acab 100644 --- a/source/libr2c2/simplecontroller.cpp +++ b/source/libr2c2/simplecontroller.cpp @@ -1,4 +1,3 @@ -#include #include #include #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); } diff --git a/source/libr2c2/speedquantizer.cpp b/source/libr2c2/speedquantizer.cpp index 1098d43..9fa127c 100644 --- a/source/libr2c2/speedquantizer.cpp +++ b/source/libr2c2/speedquantizer.cpp @@ -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); } diff --git a/source/libr2c2/timetable.cpp b/source/libr2c2/timetable.cpp index 82c5411..9fd44df 100644 --- a/source/libr2c2/timetable.cpp +++ b/source/libr2c2/timetable.cpp @@ -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(name.substr(space+1)); return train.get_layout().get_zone(name.substr(0, space), number); } @@ -263,7 +263,7 @@ template 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(); } @@ -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"); } diff --git a/source/libr2c2/track.cpp b/source/libr2c2/track.cpp index cf496c4..2cb9518 100644 --- a/source/libr2c2/track.cpp +++ b/source/libr2c2/track.cpp @@ -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< &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 &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]; } diff --git a/source/libr2c2/trackiter.cpp b/source/libr2c2/trackiter.cpp index c5663f2..c636d27 100644 --- a/source/libr2c2/trackiter.cpp +++ b/source/libr2c2/trackiter.cpp @@ -1,5 +1,4 @@ #include -#include #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; } diff --git a/source/libr2c2/trackpart.cpp b/source/libr2c2/trackpart.cpp index 79e183b..2b3809d 100644 --- a/source/libr2c2/trackpart.cpp +++ b/source/libr2c2/trackpart.cpp @@ -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]; } diff --git a/source/libr2c2/tracktype.cpp b/source/libr2c2/tracktype.cpp index b6971ca..c7a6aef 100644 --- a/source/libr2c2/tracktype.cpp +++ b/source/libr2c2/tracktype.cpp @@ -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; } diff --git a/source/libr2c2/train.cpp b/source/libr2c2/train.cpp index 5f1b46b..099e761 100644 --- a/source/libr2c2/train.cpp +++ b/source/libr2c2/train.cpp @@ -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()) - 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(); diff --git a/source/libr2c2/vehicle.cpp b/source/libr2c2/vehicle.cpp index cf00c77..1699fd8 100644 --- a/source/libr2c2/vehicle.cpp +++ b/source/libr2c2/vehicle.cpp @@ -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]; } diff --git a/source/libr2c2/vehicletype.cpp b/source/libr2c2/vehicletype.cpp index 9f88146..720b922 100644 --- a/source/libr2c2/vehicletype.cpp +++ b/source/libr2c2/vehicletype.cpp @@ -1,4 +1,5 @@ #include +#include #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 diff --git a/source/libr2c2/zone.cpp b/source/libr2c2/zone.cpp index 28b178a..eddcfc9 100644 --- a/source/libr2c2/zone.cpp +++ b/source/libr2c2/zone.cpp @@ -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(); } diff --git a/source/network/server.cpp b/source/network/server.cpp index c9a56e3..c0a6946 100644 --- a/source/network/server.cpp +++ b/source/network/server.cpp @@ -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()); } diff --git a/source/remote/remote.cpp b/source/remote/remote.cpp index 07395da..b60d11f 100644 --- a/source/remote/remote.cpp +++ b/source/remote/remote.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #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"); -- 2.43.0