1 /* Copyright (c) 2018. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SIMGRID_EXCEPTIONS_HPP
7 #define SIMGRID_EXCEPTIONS_HPP
9 /** @file exception.hpp SimGrid-specific Exceptions
11 * Defines all possible exception that could occur in a SimGrid library.
15 #include <simgrid/exception.hpp>
17 #include <xbt/exception.hpp>
23 /** Ancestor class of all SimGrid exception */
24 class exception : public std::runtime_error {
26 exception() : std::runtime_error("") {}
27 exception(const char* message) : std::runtime_error(message) {}
30 /** Exception raised when a timeout elapsed */
31 class timeout_error : public simgrid::exception {
34 /** Exception raised when an host fails */
35 class host_failure : public simgrid::exception {
38 /** Exception raised when a communication fails because of the network */
39 class network_failure : public simgrid::exception {
42 /** Exception raised when something got canceled before completion */
43 class canceled_error : public simgrid::exception {
46 } // namespace simgrid
48 /** A legacy exception
50 * It is defined by a category and a value within that category (as well as
51 * an optional error message).
53 * This used to be a structure for C exceptions but it has been retrofitted
54 * as a C++ exception and some of its data has been moved in the
55 * @ref WithContextException base class. We should deprecate it and replace it
56 * with either C++ different exceptions or `std::system_error` which already
57 * provides this (category + error code) logic.
61 class XBT_PUBLIC xbt_ex : public simgrid::exception, public simgrid::xbt::WithContextException {
63 xbt_ex() : simgrid::exception() {}
67 * @param throwpoint Throw point (use XBT_THROW_POINT)
68 * @param message Exception message
70 xbt_ex(simgrid::xbt::ThrowPoint throwpoint, const char* message)
71 : simgrid::exception(message), simgrid::xbt::WithContextException(throwpoint, simgrid::xbt::backtrace())
75 ~xbt_ex(); // DO NOT define it here -- see ex.cpp for a rationale
77 /** Category (what went wrong) */
78 xbt_errcat_t category = unknown_error;
80 /** Why did it went wrong */