Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
927790df1697e4b017f07a0fe9f607e083f32895
[simgrid.git] / include / xbt / ex.hpp
1 /* Copyright (c) 2005-2018. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_XBT_EX_HPP
7 #define SIMGRID_XBT_EX_HPP
8
9 #include <simgrid/exception.hpp>
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 simgrid::exception, public simgrid::xbt::WithContextException {
29 public:
30   xbt_ex() : simgrid::exception() {}
31
32   /**
33    *
34    * @param throwpoint Throw point (use XBT_THROW_POINT)
35    * @param message    Exception message
36    */
37   xbt_ex(simgrid::xbt::ThrowPoint throwpoint, const char* message)
38       : simgrid::exception(message), simgrid::xbt::WithContextException(throwpoint, simgrid::xbt::backtrace())
39   {}
40
41   ~xbt_ex(); // DO NOT define it here -- see ex.cpp for a rationale
42
43   /** Category (what went wrong) */
44   xbt_errcat_t category = unknown_error;
45
46   /** Why did it went wrong */
47   int value = 0;
48
49 };
50
51 #endif