X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/375fd7283ef0853cc5d023747efc9f3821ba97ca..c58278cb019a1db459dd698bc4ec8e313aa53b59:/include/xbt/exception.hpp diff --git a/include/xbt/exception.hpp b/include/xbt/exception.hpp index 544f6ae247..e214640759 100644 --- a/include/xbt/exception.hpp +++ b/include/xbt/exception.hpp @@ -33,7 +33,7 @@ namespace xbt { */ typedef std::vector Backtrace; -/** The location of where an exception has been throwed +/** The location of where an exception has been thrown * * This is a tuple (__FILE__, __LINE__, __func__) and can be created with * @ref XBT_THROW_POINT. @@ -43,10 +43,12 @@ typedef std::vector Backtrace; class ThrowPoint { public: ThrowPoint() = default; - explicit ThrowPoint(const char* file, int line, const char* function) : file(file), line(line), function(function) {} - const char* file = nullptr; - int line = 0; - const char* function = nullptr; + explicit ThrowPoint(const char* file, int line, const char* function) : file_(file), line_(line), function_(function) + { + } + const char* file_ = nullptr; + int line_ = 0; + const char* function_ = nullptr; }; /** Create a ThrowPoint with (__FILE__, __LINE__, __func__) */ @@ -55,29 +57,21 @@ class ThrowPoint { /** A base class for exceptions with context * * This is a base class for exceptions which store additional contextual - * infomations about them: backtrace, throw point, simulated process name - * and PID, etc. - * - * You are not expected to inherit from it. Instead of you use should - * @ref XBT_THROW an exception which will throw a subclass of your original - * exception with those additional features. - * - * However, you can try `dynamic_cast` an exception to this type in order to - * get contextual information about the exception. + * information: backtrace, throw point, simulated process name, PID, etc. */ -class XBT_PUBLIC WithContextException { +class XBT_PUBLIC ContextedException { public: - WithContextException() : + ContextedException() : backtrace_(simgrid::xbt::backtrace()), procname_(xbt_procname()), pid_(xbt_getpid()) {} - explicit WithContextException(Backtrace bt) : backtrace_(std::move(bt)), procname_(xbt_procname()), pid_(xbt_getpid()) + explicit ContextedException(Backtrace bt) : backtrace_(std::move(bt)), procname_(xbt_procname()), pid_(xbt_getpid()) {} - explicit WithContextException(ThrowPoint throwpoint, Backtrace bt) + explicit ContextedException(ThrowPoint throwpoint, Backtrace bt) : backtrace_(std::move(bt)), procname_(xbt_procname()), pid_(xbt_getpid()), throwpoint_(throwpoint) {} - virtual ~WithContextException(); + virtual ~ContextedException(); Backtrace const& backtrace() const { return backtrace_; @@ -102,43 +96,6 @@ private: int pid_; /**< PID of the process who thrown this */ ThrowPoint throwpoint_; }; - -/** Internal class used to mixin an exception E with WithContextException */ -template -class WithContext : public E, public WithContextException -{ -public: - static_assert(not std::is_base_of::value, "Trying to appli WithContext twice"); - - explicit WithContext(E exception) : E(std::move(exception)) {} - WithContext(E exception, ThrowPoint throwpoint, Backtrace backtrace) : - E(std::move(exception)), - WithContextException(throwpoint, std::move(backtrace)) {} - WithContext(E exception, Backtrace backtrace) : - E(std::move(exception)), - WithContextException(std::move(backtrace)) {} - WithContext(E exception, WithContextException context) : - E(std::move(exception)), - WithContextException(std::move(context)) {} - ~WithContext() override = default; -}; - -/** Throw a C++ exception with some context - * - * @param e Exception to throw - * @ingroup XBT_ex - */ -#define XBT_THROW(e) \ - throw WithContext(std::move(exception), throwpoint, simgrid::xbt::backtrace()) - -/** Throw a C++ exception with a context and a nexted exception/cause - * - * @param e Exception to throw - * @ingroup XBT_ex - */ -#define XBT_THROW_NESTED(e) \ - std::throw_with_nested(WithContext(std::move(exception), throwpoint, simgrid::xbt::backtrace())) - } }