X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/9d7dca1d2de1e6d67027e4ba33fefe1eb09550e3..4634214e18b847f6346048fa12179d3d99ae82c9:/include/xbt/exception.hpp diff --git a/include/xbt/exception.hpp b/include/xbt/exception.hpp index 4391ffec6d..8fa032d966 100644 --- a/include/xbt/exception.hpp +++ b/include/xbt/exception.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2005-2016. 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. */ @@ -40,10 +40,10 @@ typedef std::vector Backtrace; * * @ingroup XBT_ex */ -struct ThrowPoint { - ThrowPoint() {} - ThrowPoint(const char* file, int line, const char* function) : - file(file), line(line), function(function) {} +class ThrowPoint { + public: + ThrowPoint() = default; + explicit ThrowPoint(const char* file, int line, const char* function) : file(file), line(line), function(function) {} const char* file = nullptr; int line = 0; const char* function = nullptr; @@ -61,27 +61,21 @@ struct ThrowPoint { * You are not expected to inherit from it. Instead of you use should * @ref XBT_THROW an exception which will throw a subclass of your original * exception with those additional features. - * + * * However, you can try `dynamic_cast` an exception to this type in order to * get contextual information about the exception. */ -XBT_PUBLIC_CLASS WithContextException { +class XBT_PUBLIC WithContextException { public: WithContextException() : backtrace_(simgrid::xbt::backtrace()), procname_(xbt_procname()), pid_(xbt_getpid()) {} - WithContextException(Backtrace bt) : - backtrace_(std::move(bt)), - procname_(xbt_procname()), - pid_(xbt_getpid()) + explicit WithContextException(Backtrace bt) : backtrace_(std::move(bt)), procname_(xbt_procname()), pid_(xbt_getpid()) {} - WithContextException(ThrowPoint throwpoint, Backtrace bt) : - backtrace_(std::move(bt)), - procname_(xbt_procname()), - pid_(xbt_getpid()), - throwpoint_(throwpoint) + explicit WithContextException(ThrowPoint throwpoint, Backtrace bt) + : backtrace_(std::move(bt)), procname_(xbt_procname()), pid_(xbt_getpid()), throwpoint_(throwpoint) {} virtual ~WithContextException(); Backtrace const& backtrace() const @@ -103,12 +97,9 @@ template class WithContext : public E, public WithContextException { public: + static_assert(not std::is_base_of::value, "Trying to appli WithContext twice"); - static_assert(!std::is_base_of::value, - "Trying to appli WithContext twice"); - - WithContext(E exception) : - E(std::move(exception)) {} + explicit WithContext(E exception) : E(std::move(exception)) {} WithContext(E exception, ThrowPoint throwpoint, Backtrace backtrace) : E(std::move(exception)), WithContextException(throwpoint, std::move(backtrace)) {} @@ -118,7 +109,7 @@ public: WithContext(E exception, WithContextException context) : E(std::move(exception)), WithContextException(std::move(context)) {} - ~WithContext() override {} + ~WithContext() override = default; }; /** Throw a C++ exception with some context