diff options
-rw-r--r-- | lib/src/network.cpp | 20 | ||||
-rw-r--r-- | src/analysis_tools.cpp | 10 |
2 files changed, 27 insertions, 3 deletions
diff --git a/lib/src/network.cpp b/lib/src/network.cpp index 43b0fab..1edc973 100644 --- a/lib/src/network.cpp +++ b/lib/src/network.cpp @@ -1,6 +1,22 @@ #include "network.hpp" +class nanException: public std::exception +{ + virtual const char* what() const throw() + { + return "The linear problem returned NaN."; + } +} nanex; + +class nofuseException: public std::exception +{ + virtual const char* what() const throw() + { + return "No valid fuse was available to break."; + } +} nofuseex; + network::network(const graph& G, cholmod_common *c) : c(c), G(G), fuses(G.edges.size(), false), thresholds(G.edges.size(), 1) { b = CHOL_F(zeros)(G.vertices.size(), 1, CHOLMOD_REAL, c); for (unsigned i = 0; i < G.edges.size(); i++) { @@ -166,7 +182,7 @@ current_info network::get_current_info() { cholmod_dense *x = CHOL_F(solve)(CHOLMOD_A, factor, b, c); if (((double *)x->x)[0] != ((double *)x->x)[0]) { - exit(2); + throw nanex; } cholmod_dense *y = CHOL_F(allocate_dense)(G.edges.size(), 1, G.edges.size(), CHOLMOD_REAL, c); @@ -231,7 +247,7 @@ void network::fracture(hooks& m, double cutoff) { } if (max_pos == UINT_MAX) { - exit(3); + throw nofuseex; } this->break_edge(max_pos); diff --git a/src/analysis_tools.cpp b/src/analysis_tools.cpp index 778e713..bc8095e 100644 --- a/src/analysis_tools.cpp +++ b/src/analysis_tools.cpp @@ -1,6 +1,14 @@ #include "analysis_tools.hpp" +class badcycleException: public std::exception +{ + virtual const char* what() const throw() + { + return "Could not find a valid cycle on the broken system."; + } +} badcycleex; + template <class T> bool is_shorter(const std::list<T> &l1, const std::list<T> &l2) { return l1.size() < l2.size(); @@ -118,6 +126,6 @@ std::list<unsigned> find_minimal_crack(const Graph& G, const network& n) { return cycles.front(); } - exit(5); + throw badcycleex; } |