Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4208eead8924d1ab977fedf3e42e9135f1e9de90
[simgrid.git] / include / xbt / ex.hpp
1 /* Copyright (c) 2005-2018. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SIMGRID_XBT_EX_HPP
8 #define SIMGRID_XBT_EX_HPP
9
10 #include <stdexcept>
11 #include <xbt/exception.hpp>
12
13 #include <xbt/ex.h>
14
15 /** A legacy exception
16  *
17  *  It is defined by a category and a value within that category (as well as
18  *  an optional error message).
19  *
20  *  This used to be a structure for C exceptions but it has been retrofitted
21  *  as a C++ exception and some of its data has been moved in the
22  *  @ref WithContextException base class. We should deprecate it and replace it
23  *  with either C++ different exceptions or `std::system_error` which already
24  *  provides this (category + error code) logic.
25  *
26  *  @ingroup XBT_ex_c
27  */
28 struct XBT_PUBLIC() xbt_ex :
29   std::runtime_error,
30   simgrid::xbt::WithContextException {
31
32   xbt_ex() :
33     std::runtime_error("")
34   {}
35
36   /**
37    *
38    * @param throwpoint Throw point (use XBT_THROW_POINT)
39    * @param message    Exception message
40    */
41   xbt_ex(simgrid::xbt::ThrowPoint throwpoint, const char* message) :
42     std::runtime_error(message),
43     simgrid::xbt::WithContextException(throwpoint, simgrid::xbt::backtrace())
44   {}
45
46   ~xbt_ex();
47
48   /** Category (what went wrong) */
49   xbt_errcat_t category = unknown_error;
50
51   /** Why did it went wrong */
52   int value = 0;
53
54 };
55
56 #endif