-
-/** Internal class used to mixin an exception E with WithContextException */
-template<class E>
-class WithContext : public E, public WithContextException
-{
-public:
- static_assert(not std::is_base_of<WithContextException, E>::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<E>(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<E>(std::move(exception), throwpoint, simgrid::xbt::backtrace()))
-