Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c1dcfb8a1a9f7ed7fa34ef6c8f4d8f8aa8b88690
[simgrid.git] / include / xbt / ex.hpp
1 /* Copyright (c) 2005-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /*  Copyright (c) 2002-2004 Ralf S. Engelschall <rse@engelschall.com>       */
5 /*  Copyright (c) 2002-2004 The OSSP Project <http://www.ossp.org/>         */
6 /*  Copyright (c) 2002-2004 Cable & Wireless <http://www.cw.com/>           */
7 /*  All rights reserved.                                                    */
8
9 /* This code is inspirated from the OSSP version (as retrieved back in 2004)*/
10 /* It was heavily modified to fit the SimGrid framework.                    */
11
12 /* The OSSP version has the following copyright notice:
13 **  OSSP ex - Exception Handling
14 **  Copyright (c) 2002-2004 Ralf S. Engelschall <rse@engelschall.com>
15 **  Copyright (c) 2002-2004 The OSSP Project <http://www.ossp.org/>
16 **  Copyright (c) 2002-2004 Cable & Wireless <http://www.cw.com/>
17 **
18 **  This file is part of OSSP ex, an exception handling library
19 **  which can be found at http://www.ossp.org/pkg/lib/ex/.
20 **
21 **  Permission to use, copy, modify, and distribute this software for
22 **  any purpose with or without fee is hereby granted, provided that
23 **  the above copyright notice and this permission notice appear in all
24 **  copies.
25 **
26 **  THIS SOFTWARE IS PROVIDED `AS IS'' AND ANY EXPRESSED OR IMPLIED
27 **  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 **  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 **  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
30 **  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 **  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 **  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
33 **  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
34 **  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35 **  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
36 **  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 **  SUCH DAMAGE.
38  */
39
40 /* The extensions made for the SimGrid project can either be distributed    */
41 /* under the same license, or under the LGPL v2.1                           */
42
43 #ifndef SIMGRID_XBT_EX_HPP
44 #define SIMGRID_XBT_EX_HPP
45
46 #include <stdexcept>
47 #include <xbt/exception.hpp>
48
49 #include <xbt/ex.h>
50
51 /** (Deprecated) Generic exception
52  *
53  *  An error is defined by a category and a value within that category.
54  *
55  *  This used to be a structure for C exceptions but it has been retrofitted
56  *  as a C++ exception and some of its data has been moved in the
57  *  WithContextException base class. We should deprecate it and replace it
58  *  with either C++ different exceptions or `std::system_error` which already
59  *  provides this (category + error code) logic.
60  */
61 struct XBT_PUBLIC() xbt_ex :
62   public std::runtime_error,
63   public simgrid::xbt::WithContextException {
64 public:
65
66   xbt_ex() :
67     std::runtime_error("")
68   {}
69
70   /**
71    *
72    * @param throwpoint Throw point (use XBT_THROW_POINT)
73    * @param message    Exception message
74    */
75   xbt_ex(simgrid::xbt::ThrowPoint throwpoint, const char* message) :
76     std::runtime_error(message),
77     simgrid::xbt::WithContextException(throwpoint, simgrid::xbt::backtrace())
78   {}
79
80   ~xbt_ex() override;
81
82   /** Category (what went wrong) */
83   xbt_errcat_t category;
84
85   /** Why did it went wrong */
86   int value;
87
88 };
89
90 #endif