From: Martin Quinson Date: Sun, 26 Aug 2018 00:09:00 +0000 (+0200) Subject: implement THROW_IMPOSSIBLE and THROW_UNIMPLEMENTED with std::runtime_error directly X-Git-Tag: v3_21~161 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/be3bc4127b2e514da9b6d4baab02e3cc22a5617a implement THROW_IMPOSSIBLE and THROW_UNIMPLEMENTED with std::runtime_error directly --- diff --git a/include/simgrid/Exception.hpp b/include/simgrid/Exception.hpp index 9d398b4ac5..7a2ba1ed83 100644 --- a/include/simgrid/Exception.hpp +++ b/include/simgrid/Exception.hpp @@ -11,19 +11,11 @@ * Defines all possible exception that could occur in a SimGrid library. */ -#include -#include -#include -#include -#include - -#include #include -#include #include -#include -#include // xbt_procname -#include // xbt_getpid + +#include +#include namespace simgrid { namespace xbt { @@ -133,6 +125,7 @@ class NetworkFailureException : public xbt_ex { /** Exception raised when something got canceled before completion */ class CancelException : public xbt_ex { }; + } // namespace simgrid #endif diff --git a/include/xbt/ex.h b/include/xbt/ex.h index 564863b0f9..ed4056626b 100644 --- a/include/xbt/ex.h +++ b/include/xbt/ex.h @@ -70,23 +70,17 @@ 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__) +XBT_ATTRIB_NORETURN void xbt_throw_impossible(const char* file, int line, const char* func); /** Throw an exception because something impossible happened * @ingroup XBT_ex_c */ -#define THROW_IMPOSSIBLE \ - THROWF(unknown_error, 0, "The Impossible Did Happen (yet again)") +#define THROW_IMPOSSIBLE xbt_throw_impossible(__FILE__, __LINE__, __func__) /** Throw an exception because something unimplemented stuff has been attempted * @ingroup XBT_ex_c */ -#define THROW_UNIMPLEMENTED \ - THROWF(unknown_error, 0, "Function %s unimplemented",__func__) - -/** Throw an exception because some dead code was reached - * @ingroup XBT_ex_c - */ -#define THROW_DEADCODE \ - THROWF(unknown_error, 0, "Function %s was supposed to be DEADCODE, but it's not",__func__) +XBT_ATTRIB_NORETURN void xbt_throw_unimplemented(const char* file, int line, const char* func); +#define THROW_UNIMPLEMENTED xbt_throw_unimplemented(__FILE__, __LINE__, __func__) /** Die because something impossible happened * @ingroup XBT_ex_c diff --git a/src/xbt/exception.cpp b/src/xbt/exception.cpp index d2712eef07..c14e9aed27 100644 --- a/src/xbt/exception.cpp +++ b/src/xbt/exception.cpp @@ -3,22 +3,13 @@ /* 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. */ -#include - -#include -#include -#include -#include -#include -#include -#include - #include "simgrid/Exception.hpp" -#include #include -#include #include +#include +#include + XBT_LOG_EXTERNAL_CATEGORY(xbt); XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_exception, xbt, "Exceptions"); @@ -194,4 +185,17 @@ void installExceptionHandler() } } // namespace xbt +} // namespace simgrid + +void xbt_throw_impossible(const char* file, int line, const char* func) +{ + std::stringstream ss; + ss << file << ":" << line << ":" << func << ": The Impossible Did Happen (yet again). Please report this bug."; + throw std::runtime_error(ss.str()); +} +void xbt_throw_unimplemented(const char* file, int line, const char* func) +{ + std::stringstream ss; + ss << file << ":" << line << ":" << func << ": Feature unimplemented yet. Please report this bug."; + throw std::runtime_error(ss.str()); }