1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-27 14:37:16 +00:00

Rationalize some std::exception stuff.

This commit is contained in:
Arthur O'Dwyer 2021-03-21 17:56:38 -04:00
parent 4c10b17b7e
commit 1761b02b90
8 changed files with 32 additions and 34 deletions

View File

@ -267,7 +267,7 @@ EX namespace bt {
return path(h, d, bd_up_left, {bd_right, bd_down});
}
}
throw hr_wrong_dir();
throw hr_exception("wrong dir");
}
case gBinary4: {
switch(d) {
@ -286,7 +286,7 @@ EX namespace bt {
else
return path(h, 4, 2, {3, 4, 1});
default:
throw hr_wrong_dir();
throw hr_exception("wrong dir");
}
}
case gTernary: {
@ -306,7 +306,7 @@ EX namespace bt {
else
return path(h, 5, 3, {4, 5, 2});
default:
throw hr_wrong_dir();
throw hr_exception("wrong dir");
}
}
#if MAXMDIM >= 4
@ -342,7 +342,7 @@ EX namespace bt {
else
return path(h, 7, 6, {8, 7, parent->c.spin(8) ^ 2});
default:
throw hr_wrong_dir();
throw hr_exception("wrong dir");
}
}
case gHoroRec: {
@ -370,7 +370,7 @@ EX namespace bt {
parent->cmove(6);
return path(h, 5, 3, {6, 2, parent->c.spin(6)});
default:
throw hr_wrong_dir();
throw hr_exception("wrong dir");
}
}
case gHoroTris: {
@ -387,7 +387,7 @@ EX namespace bt {
else return path(h, d, d, {7, d, 9-d-s});
}
default:
throw hr_wrong_dir();
throw hr_exception("wrong dir");
}
}
case gHoroHex: {
@ -422,12 +422,12 @@ EX namespace bt {
return path(h, 12, (z+1)%3+3, {13, z+6});
}
default:
throw hr_wrong_dir();
throw hr_exception("wrong dir");
}
}
#endif
default:
throw hr_wrong_geometry();
throw hr_exception("wrong geometry");
}
}
@ -436,7 +436,7 @@ EX namespace bt {
else if(type_of(h) == 6) return bd_down;
else if(mapside(h) == 1) return bd_left;
else if(mapside(h) == -1) return bd_right;
else throw hr_wrong_dir();
else throw hr_exception("wrong dir");
}
transmatrix relative_matrix(heptagon *h2, heptagon *h1, const hyperpoint& hint) override {

View File

@ -786,7 +786,7 @@ EX namespace dialog {
#endif
if(reaction) reaction();
}
catch(hr_parse_exception&) {
catch(const hr_parse_exception&) {
}
}

View File

@ -288,7 +288,7 @@ EX namespace history {
auto p = build_shortest_path(start, target);
path_for_lineanimation = p;
}
catch(hr_shortest_path_exception&) {
catch(const hr_shortest_path_exception&) {
addMessage("Could not build a path");
return;
}

12
hyper.h
View File

@ -98,14 +98,12 @@ using std::asinh;
using std::acosh;
#endif
struct hr_exception: std::exception { hr_exception() {} };
struct hr_shortest_path_exception: hr_exception { };
struct hr_exception : std::runtime_error {
explicit hr_exception() : std::runtime_error("hr_exception") {}
explicit hr_exception(const std::string& s) : std::runtime_error(s.c_str()) {}
};
struct hr_wrong_dir: hr_exception { };
struct hr_wrong_geometry: hr_exception { };
struct hr_exception_str: std::exception { string s; hr_exception_str(const string& s) : s(s) {} const char* what() { return s.c_str(); }};
struct hr_shortest_path_exception { };
// genus (in grammar)
#define GEN_M 0

View File

@ -427,11 +427,11 @@ EX namespace sn {
case 8:
return xpush(bw*(4.5-j)) * zpush(-1) * ypush(bw*(i-7));
default:
throw hr_wrong_dir();
throw hr_exception("wrong dir");
}
}
default: throw hr_wrong_geometry();
default: throw hr_exception("wrong geometry");
}
}

View File

@ -503,12 +503,12 @@ EX void generate_track() {
}
else find_track(s, 0, length);
}
catch(hr_track_failure&) {
catch(const hr_track_failure&) {
race_try++;
gamegen_failure = true;
return;
}
catch(hr_shortest_path_exception&) {
catch(const hr_shortest_path_exception&) {
addMessage("error: could not build path");
gamegen_failure = true;
racing::on = false;

View File

@ -402,7 +402,7 @@ struct hrmap_notknot : hrmap {
auto d1 = u->where->c.spin(d);
auto z = x->zebraval;
if(z & 6) {
throw hr_exception_str("zebraval failure!");
throw hr_exception("zebraval failure!");
exit(3);
x->zebraval = 0;
}
@ -418,7 +418,7 @@ struct hrmap_notknot : hrmap {
void add_to_unify(ucover *a, ucover *b) {
if(a->where != b->where)
throw hr_exception_str("unification error");
throw hr_exception("unification error");
unify.emplace_back(a, b);
};
@ -641,7 +641,7 @@ struct hrmap_notknot : hrmap {
if(u->where == all[0]->where)
for(auto& lo: to_unloop)
if(!make_loop(u, 1, lo))
throw hr_exception_str("given loop goes through a wall");
throw hr_exception("given loop goes through a wall");
if(loop_any && u->where == all[0]->where) {
auto us = all[0];
@ -685,7 +685,7 @@ struct hrmap_notknot : hrmap {
all[0]->parentdir = -1;
if(all[0]->where->zebraval & 1)
throw hr_exception_str("error: starting inside a wall");
throw hr_exception("error: starting inside a wall");
remove_marked_walls = false;
bool first = true;
@ -712,7 +712,7 @@ struct hrmap_notknot : hrmap {
uf->state |= 2; uf->merged_into = ut;
if(uf->where != ut->where)
throw hr_exception_str("where confusion");
throw hr_exception("where confusion");
for(int d=0; d<uf->where->type; d++) {
cmov(uf->where, d);
auto d1 = uf->where->c.spin(d);
@ -881,9 +881,9 @@ struct hrmap_notknot : hrmap {
cmov(u->where, d);
auto d1 = u->where->c.spin(d);
if(u->ptr[d] && u->ptr[d]->result == nullptr)
throw hr_exception_str(lalign(0, "connection to null in state ", u->ptr[d]->state, " from state ", u->state, " i=", i, " .. ", u->ptr[d]->index));
throw hr_exception(lalign(0, "connection to null in state ", u->ptr[d]->state, " from state ", u->state, " i=", i, " .. ", u->ptr[d]->index));
if(u->ptr[d] && u->ptr[d]->ptr[d1] != u)
throw hr_exception_str("wrong connection");
throw hr_exception("wrong connection");
if(u->ptr[d])
u->result->c.connect(d, u->ptr[d]->result, d1, false);
else
@ -973,8 +973,8 @@ struct hrmap_notknot : hrmap {
ray::volumetric::vmap[c] = 0x00000001;
}
} catch(hr_exception_str& s) {
println(hlog, "exception: ", s.s);
} catch(const hr_exception& s) {
println(hlog, "exception: ", s.what());
throw;
}
}

View File

@ -600,7 +600,7 @@ EX void buildRug() {
else if(v > w && v > w2)
addTriangle(v, w, w2);
}
catch(out_of_range&) {}
catch(const std::out_of_range&) {}
}
println(hlog, "vertices = ", isize(points), " triangles= ", isize(triangles));
@ -1218,7 +1218,7 @@ EX void init_model() {
"Use a different projection to fix this."
);
}
catch(rug_exception) {
catch(const rug_exception&) {
close();
clear_model();
}
@ -1353,7 +1353,7 @@ EX void actDraw() {
perform_finger();
#endif
}
catch(rug_exception) {
catch(const rug_exception&) {
rug::close();
}
}