From: Arnaud Giersch Date: Tue, 2 Jul 2019 13:30:30 +0000 (+0200) Subject: Define proper exceptions subclasses. X-Git-Tag: v3.23.2~42 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/750ecf3b5990073a757a9535f5227491a271e16a Define proper exceptions subclasses. --- diff --git a/include/simgrid/Exception.hpp b/include/simgrid/Exception.hpp index 685f36deb9..8c1e0f7917 100644 --- a/include/simgrid/Exception.hpp +++ b/include/simgrid/Exception.hpp @@ -56,6 +56,19 @@ public: /** Create a ThrowPoint with (__FILE__, __LINE__, __func__) */ #define XBT_THROW_POINT \ ::simgrid::xbt::ThrowPoint(__FILE__, __LINE__, __func__, simgrid::xbt::Backtrace(), xbt_procname(), xbt_getpid()) + +class XBT_PUBLIC ImpossibleError : public std::logic_error { +public: + explicit ImpossibleError(const std::string& arg) : std::logic_error(arg) {} + ~ImpossibleError(); +}; + +class XBT_PUBLIC UnimplementedError : public std::logic_error { +public: + explicit UnimplementedError(const std::string& arg) : std::logic_error(arg) {} + ~UnimplementedError(); +}; + } // namespace xbt /** Ancestor class of all SimGrid exception */ diff --git a/src/xbt/exception.cpp b/src/xbt/exception.cpp index 73f18098f6..b3f4c51dd8 100644 --- a/src/xbt/exception.cpp +++ b/src/xbt/exception.cpp @@ -70,6 +70,9 @@ const char* xbt_ex_catname(xbt_errcat_t cat) namespace simgrid { namespace xbt { +ImpossibleError::~ImpossibleError() = default; +UnimplementedError::~UnimplementedError() = default; + void log_exception(e_xbt_log_priority_t prio, const char* context, std::exception const& exception) { try { @@ -181,11 +184,11 @@ void xbt_throw_impossible(const char* file, int line, const char* func) { std::stringstream ss; ss << file << ":" << line << ":" << func << ": The Impossible Did Happen (yet again). Please report this bug."; - throw std::runtime_error(ss.str()); + throw simgrid::xbt::ImpossibleError(ss.str()); } void xbt_throw_unimplemented(const char* file, int line, const char* func) { std::stringstream ss; ss << file << ":" << line << ":" << func << ": Feature unimplemented yet. Please report this bug."; - throw std::runtime_error(ss.str()); + throw simgrid::xbt::UnimplementedError(ss.str()); }