Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Create some simgrid::exception, and make xbt_ex one of them
authorMartin Quinson <martin.quinson@loria.fr>
Fri, 24 Aug 2018 15:46:17 +0000 (17:46 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Fri, 24 Aug 2018 16:42:40 +0000 (18:42 +0200)
include/simgrid/exception.hpp [new file with mode: 0644]
include/xbt/ex.h
include/xbt/ex.hpp
tools/cmake/DefinePackages.cmake

diff --git a/include/simgrid/exception.hpp b/include/simgrid/exception.hpp
new file mode 100644 (file)
index 0000000..bab34d8
--- /dev/null
@@ -0,0 +1,43 @@
+/* Copyright (c) 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. */
+
+#ifndef SIMGRID_EXCEPTIONS_HPP
+#define SIMGRID_EXCEPTIONS_HPP
+
+/** @file exception.hpp SimGrid-specific Exceptions
+ *
+ *  Defines all possible exception that could occur in a SimGrid library.
+ */
+
+#include <exception>
+
+namespace simgrid {
+
+/** Ancestor class of all SimGrid exception */
+class exception : public std::runtime_error {
+public:
+  exception() : std::runtime_error("") {}
+  exception(const char* message) : std::runtime_error(message) {}
+};
+
+/** Exception raised when a timeout elapsed */
+class timeout_error : public simgrid::exception {
+};
+
+/** Exception raised when an host fails */
+class host_failure : public simgrid::exception {
+};
+
+/** Exception raised when a communication fails because of the network */
+class network_failure : public simgrid::exception {
+};
+
+/** Exception raised when something got canceled before completion */
+class cancel_error : public simgrid::exception {
+};
+
+} // namespace simgrid
+
+#endif
index dc6596c..564863b 100644 (file)
@@ -70,13 +70,13 @@ XBT_ATTRIB_NORETURN XBT_PUBLIC void _xbt_throw(char* message, xbt_errcat_t errca
  */
 #define THROWF(c, v, ...)       _xbt_throw(bprintf(__VA_ARGS__), (xbt_errcat_t) c, v, __FILE__, __LINE__, __func__)
 
-/** Throw an exception because someting impossible happened
+/** Throw an exception because something impossible happened
  *  @ingroup XBT_ex_c
  */
 #define THROW_IMPOSSIBLE \
   THROWF(unknown_error, 0, "The Impossible Did Happen (yet again)")
 
-/** Throw an exception because someting unimplemented stuff has been attempted
+/** Throw an exception because something unimplemented stuff has been attempted
  *  @ingroup XBT_ex_c
  */
 #define THROW_UNIMPLEMENTED \
index 9b6ff5f..927790d 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (c) 2005-2018. 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. */
@@ -7,6 +6,7 @@
 #ifndef SIMGRID_XBT_EX_HPP
 #define SIMGRID_XBT_EX_HPP
 
+#include <simgrid/exception.hpp>
 #include <stdexcept>
 #include <xbt/exception.hpp>
 
  *
  *  @ingroup XBT_ex_c
  */
-class XBT_PUBLIC xbt_ex : public std::runtime_error, public simgrid::xbt::WithContextException {
+class XBT_PUBLIC xbt_ex : public simgrid::exception, public simgrid::xbt::WithContextException {
 public:
-  xbt_ex() :
-    std::runtime_error("")
-  {}
+  xbt_ex() : simgrid::exception() {}
 
   /**
    *
    * @param throwpoint Throw point (use XBT_THROW_POINT)
    * @param message    Exception message
    */
-  xbt_ex(simgrid::xbt::ThrowPoint throwpoint, const char* message) :
-    std::runtime_error(message),
-    simgrid::xbt::WithContextException(throwpoint, simgrid::xbt::backtrace())
+  xbt_ex(simgrid::xbt::ThrowPoint throwpoint, const char* message)
+      : simgrid::exception(message), simgrid::xbt::WithContextException(throwpoint, simgrid::xbt::backtrace())
   {}
 
   ~xbt_ex(); // DO NOT define it here -- see ex.cpp for a rationale
index d1852d3..d12bd14 100644 (file)
@@ -670,6 +670,7 @@ set(headers_to_install
   include/simgrid/actor.h
   include/simgrid/barrier.h
   include/simgrid/engine.h
+  include/simgrid/exception.hpp
   include/simgrid/chrono.hpp
   include/simgrid/plugins/dvfs.h
   include/simgrid/plugins/energy.h