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.
16 #include <xbt/exception.hpp>
22 /** Ancestor class of all SimGrid exception */
23 class Exception : public std::runtime_error {
25 Exception() : std::runtime_error("") {}
26 Exception(const char* message) : std::runtime_error(message) {}
29 /** Exception raised when a timeout elapsed */
30 class timeout_error : public simgrid::Exception {
33 /** Exception raised when an host fails */
34 class host_failure : public simgrid::Exception {
37 /** Exception raised when a communication fails because of the network */
38 class network_failure : public simgrid::Exception {
41 /** Exception raised when something got canceled before completion */
42 class canceled_error : public simgrid::Exception {
45 } // namespace simgrid
47 /** A legacy exception
49 * It is defined by a category and a value within that category (as well as
50 * an optional error message).
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.
60 class XBT_PUBLIC xbt_ex : public simgrid::Exception, public simgrid::xbt::ContextedException {
62 xbt_ex() : simgrid::Exception() {}
66 * @param throwpoint Throw point (use XBT_THROW_POINT)
67 * @param message Exception message
69 xbt_ex(simgrid::xbt::ThrowPoint throwpoint, const char* message)
70 : simgrid::Exception(message), simgrid::xbt::ContextedException(throwpoint, simgrid::xbt::backtrace())
74 ~xbt_ex(); // DO NOT define it here -- see ex.cpp for a rationale
76 /** Category (what went wrong) */
77 xbt_errcat_t category = unknown_error;
79 /** Why did it went wrong */