diff --git a/cell.cpp b/cell.cpp index 6e4c3dd6..6533c23b 100644 --- a/cell.cpp +++ b/cell.cpp @@ -908,7 +908,7 @@ vector build_shortest_path(cell *c1, cell *c2) { while(c1 != c2) { p.push_back(c1); forCellCM(c, c1) if(celldist(c) < celldist(c1)) { c1 = c; goto next1; } - println(hlog, "could not build_shortest_path"); exit(1); + throw hr_shortest_path_exception(); next1: ; } p.push_back(c1); @@ -921,7 +921,7 @@ vector build_shortest_path(cell *c1, cell *c2) { while(c1 != c2) { p.push_back(c1); forCellCM(c, c1) if(celldistance(c, c2) < celldistance(c1, c2)) { c1 = c; goto next; } - println(hlog, "could not build_shortest_path"); exit(1); + throw hr_shortest_path_exception(); next: ; } p.push_back(c1); diff --git a/hyper.h b/hyper.h index 602194e9..af8e6e83 100644 --- a/hyper.h +++ b/hyper.h @@ -79,6 +79,9 @@ using std::asinh; using std::acosh; #endif +struct hr_exception: std::exception { hr_exception() {} }; +struct hr_shortest_path_exception: hr_exception { }; + // genus (in grammar) #define GEN_M 0 #define GEN_F 1 @@ -4547,7 +4550,7 @@ template void hread(hstream& hs, map& a) { template void hwrite(hstream& hs, const C& c, const C1& c1, const CS&... cs) { hwrite(hs, c); hwrite(hs, c1, cs...); } template void hread(hstream& hs, C& c, C1& c1, CS&... cs) { hread(hs, c); hread(hs, c1, cs...); } -struct hstream_exception : std::exception { hstream_exception() {} }; +struct hstream_exception : hr_exception { hstream_exception() {} }; struct fhstream : hstream { FILE *f; diff --git a/racing.cpp b/racing.cpp index d40027d6..f3d8e26d 100644 --- a/racing.cpp +++ b/racing.cpp @@ -301,8 +301,15 @@ void generate_track() { } } - track = build_shortest_path(s, goal); - + try { + track = build_shortest_path(s, goal); + } + catch(hr_shortest_path_exception&) { + addMessage("error: could not build path"); + gamegen_failure = true; + racing::on = false; + return; + } /* transmatrix At = spin(hrand(1000));