Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Define proper exceptions subclasses.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 2 Jul 2019 13:30:30 +0000 (15:30 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 2 Jul 2019 14:12:21 +0000 (16:12 +0200)
include/simgrid/Exception.hpp
src/xbt/exception.cpp

index 685f36d..8c1e0f7 100644 (file)
@@ -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())
 /** 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 */
 } // namespace xbt
 
 /** Ancestor class of all SimGrid exception */
index 73f1809..b3f4c51 100644 (file)
@@ -70,6 +70,9 @@ const char* xbt_ex_catname(xbt_errcat_t cat)
 namespace simgrid {
 namespace xbt {
 
 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 {
 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.";
 {
   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.";
 }
 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());
 }
 }