Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove an unused class around exceptions
[simgrid.git] / include / xbt / exception.hpp
index 3d648a1..edc0221 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2005-2017. The SimGrid Team.All rights reserved. */
+/* Copyright (c) 2005-2018. The SimGrid Team.All rights reserved. */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -55,8 +55,7 @@ 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.
+ *  information: backtrace, throw point, simulated process name, 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
@@ -65,7 +64,7 @@ class ThrowPoint {
  *  However, you can try `dynamic_cast` an exception to this type in order to
  *  get contextual information about the exception.
  */
-XBT_PUBLIC_CLASS WithContextException {
+class XBT_PUBLIC WithContextException {
 public:
   WithContextException() :
     backtrace_(simgrid::xbt::backtrace()),
@@ -83,51 +82,25 @@ public:
     return backtrace_;
   }
   int pid() const { return pid_; }
-  std::string const& processName() const { return procname_; }
-  ThrowPoint& throwPoint() { return throwpoint_; }
+  std::string const& process_name() const { return procname_; }
+  ThrowPoint& throw_point() { return throwpoint_; }
+
+  // deprecated
+  XBT_ATTRIB_DEPRECATED_v323("Please use WithContextException::process_name()") std::string const& processName() const
+  {
+    return process_name();
+  }
+  XBT_ATTRIB_DEPRECATED_v323("Please use WithContextException::throw_point()") ThrowPoint& throwPoint()
+  {
+    return throw_point();
+  }
+
 private:
   Backtrace backtrace_;
   std::string procname_; /**< Name of the process who thrown this */
   int pid_;              /**< PID of the process who thrown this */
   ThrowPoint throwpoint_;
 };
-
-/** 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()))
-
 }
 }