Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
mv link map to the engine
[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 class XBT_PUBLIC xbt_ex : public std::runtime_error, public simgrid::xbt::WithContextException {
29 public:
30   xbt_ex() :
31     std::runtime_error("")
32   {}
33
34   /**
35    *
36    * @param throwpoint Throw point (use XBT_THROW_POINT)
37    * @param message    Exception message
38    */
39   xbt_ex(simgrid::xbt::ThrowPoint throwpoint, const char* message) :
40     std::runtime_error(message),
41     simgrid::xbt::WithContextException(throwpoint, simgrid::xbt::backtrace())
42   {}
43
44   ~xbt_ex(); // DO NOT define it here -- see ex.cpp for a rationale
45
46   /** Category (what went wrong) */
47   xbt_errcat_t category = unknown_error;
48
49   /** Why did it went wrong */
50   int value = 0;
51
52 };
53
54 #endif