From: Martin Quinson Date: Fri, 24 Aug 2018 15:46:17 +0000 (+0200) Subject: Create some simgrid::exception, and make xbt_ex one of them X-Git-Tag: v3_21~186 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/58ff8ea24988e7e8b1704da2d2ab131beba7d293 Create some simgrid::exception, and make xbt_ex one of them --- diff --git a/include/simgrid/exception.hpp b/include/simgrid/exception.hpp new file mode 100644 index 0000000000..bab34d8118 --- /dev/null +++ b/include/simgrid/exception.hpp @@ -0,0 +1,43 @@ +/* Copyright (c) 2018. The SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#ifndef SIMGRID_EXCEPTIONS_HPP +#define SIMGRID_EXCEPTIONS_HPP + +/** @file exception.hpp SimGrid-specific Exceptions + * + * Defines all possible exception that could occur in a SimGrid library. + */ + +#include + +namespace simgrid { + +/** Ancestor class of all SimGrid exception */ +class exception : public std::runtime_error { +public: + exception() : std::runtime_error("") {} + exception(const char* message) : std::runtime_error(message) {} +}; + +/** Exception raised when a timeout elapsed */ +class timeout_error : public simgrid::exception { +}; + +/** Exception raised when an host fails */ +class host_failure : public simgrid::exception { +}; + +/** Exception raised when a communication fails because of the network */ +class network_failure : public simgrid::exception { +}; + +/** Exception raised when something got canceled before completion */ +class cancel_error : public simgrid::exception { +}; + +} // namespace simgrid + +#endif diff --git a/include/xbt/ex.h b/include/xbt/ex.h index dc6596c7a3..564863b0f9 100644 --- a/include/xbt/ex.h +++ b/include/xbt/ex.h @@ -70,13 +70,13 @@ XBT_ATTRIB_NORETURN XBT_PUBLIC void _xbt_throw(char* message, xbt_errcat_t errca */ #define THROWF(c, v, ...) _xbt_throw(bprintf(__VA_ARGS__), (xbt_errcat_t) c, v, __FILE__, __LINE__, __func__) -/** Throw an exception because someting impossible happened +/** Throw an exception because something impossible happened * @ingroup XBT_ex_c */ #define THROW_IMPOSSIBLE \ THROWF(unknown_error, 0, "The Impossible Did Happen (yet again)") -/** Throw an exception because someting unimplemented stuff has been attempted +/** Throw an exception because something unimplemented stuff has been attempted * @ingroup XBT_ex_c */ #define THROW_UNIMPLEMENTED \ diff --git a/include/xbt/ex.hpp b/include/xbt/ex.hpp index 9b6ff5ff32..927790df16 100644 --- a/include/xbt/ex.hpp +++ b/include/xbt/ex.hpp @@ -1,5 +1,4 @@ -/* Copyright (c) 2005-2018. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2005-2018. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -7,6 +6,7 @@ #ifndef SIMGRID_XBT_EX_HPP #define SIMGRID_XBT_EX_HPP +#include #include #include @@ -25,20 +25,17 @@ * * @ingroup XBT_ex_c */ -class XBT_PUBLIC xbt_ex : public std::runtime_error, public simgrid::xbt::WithContextException { +class XBT_PUBLIC xbt_ex : public simgrid::exception, public simgrid::xbt::WithContextException { public: - xbt_ex() : - std::runtime_error("") - {} + xbt_ex() : simgrid::exception() {} /** * * @param throwpoint Throw point (use XBT_THROW_POINT) * @param message Exception message */ - xbt_ex(simgrid::xbt::ThrowPoint throwpoint, const char* message) : - std::runtime_error(message), - simgrid::xbt::WithContextException(throwpoint, simgrid::xbt::backtrace()) + xbt_ex(simgrid::xbt::ThrowPoint throwpoint, const char* message) + : simgrid::exception(message), simgrid::xbt::WithContextException(throwpoint, simgrid::xbt::backtrace()) {} ~xbt_ex(); // DO NOT define it here -- see ex.cpp for a rationale diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index d1852d34f3..d12bd14331 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -670,6 +670,7 @@ set(headers_to_install include/simgrid/actor.h include/simgrid/barrier.h include/simgrid/engine.h + include/simgrid/exception.hpp include/simgrid/chrono.hpp include/simgrid/plugins/dvfs.h include/simgrid/plugins/energy.h