Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rename simgrid::exception into simgrid::Exception
[simgrid.git] / include / simgrid / Exception.hpp
1 /* Copyright (c) 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_EXCEPTIONS_HPP
7 #define SIMGRID_EXCEPTIONS_HPP
8
9 /** @file exception.hpp SimGrid-specific Exceptions
10  *
11  *  Defines all possible exception that could occur in a SimGrid library.
12  */
13
14 #include <exception>
15 #include <stdexcept>
16 #include <xbt/exception.hpp>
17
18 #include <xbt/ex.h>
19
20 namespace simgrid {
21
22 /** Ancestor class of all SimGrid exception */
23 class Exception : public std::runtime_error {
24 public:
25   Exception() : std::runtime_error("") {}
26   Exception(const char* message) : std::runtime_error(message) {}
27 };
28
29 /** Exception raised when a timeout elapsed */
30 class timeout_error : public simgrid::Exception {
31 };
32
33 /** Exception raised when an host fails */
34 class host_failure : public simgrid::Exception {
35 };
36
37 /** Exception raised when a communication fails because of the network */
38 class network_failure : public simgrid::Exception {
39 };
40
41 /** Exception raised when something got canceled before completion */
42 class canceled_error : public simgrid::Exception {
43 };
44
45 } // namespace simgrid
46
47 /** A legacy exception
48  *
49  *  It is defined by a category and a value within that category (as well as
50  *  an optional error message).
51  *
52  *  This used to be a structure for C exceptions but it has been retrofitted
53  *  as a C++ exception and some of its data has been moved in the
54  *  @ref WithContextException base class. We should deprecate it and replace it
55  *  with either C++ different exceptions or `std::system_error` which already
56  *  provides this (category + error code) logic.
57  *
58  *  @ingroup XBT_ex_c
59  */
60 class XBT_PUBLIC xbt_ex : public simgrid::Exception, public simgrid::xbt::ContextedException {
61 public:
62   xbt_ex() : simgrid::Exception() {}
63
64   /**
65    *
66    * @param throwpoint Throw point (use XBT_THROW_POINT)
67    * @param message    Exception message
68    */
69   xbt_ex(simgrid::xbt::ThrowPoint throwpoint, const char* message)
70       : simgrid::Exception(message), simgrid::xbt::ContextedException(throwpoint, simgrid::xbt::backtrace())
71   {
72   }
73
74   ~xbt_ex(); // DO NOT define it here -- see ex.cpp for a rationale
75
76   /** Category (what went wrong) */
77   xbt_errcat_t category = unknown_error;
78
79   /** Why did it went wrong */
80   int value = 0;
81 };
82
83 #endif