From 745db409a68b64746905d9f5caf5cadb963525be Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 7 Sep 2015 17:15:52 -0400 Subject: [PATCH] Add a constructor for CanteraError that uses format strings --- include/cantera/base/ctexceptions.h | 17 ++++++++++++++++- src/base/ctexceptions.cpp | 9 --------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/include/cantera/base/ctexceptions.h b/include/cantera/base/ctexceptions.h index bbfae008b..82c6d2067 100644 --- a/include/cantera/base/ctexceptions.h +++ b/include/cantera/base/ctexceptions.h @@ -11,6 +11,7 @@ #include #include +#include "cantera/ext/format.h" namespace Cantera { @@ -77,7 +78,21 @@ public: * generated. * @param msg Descriptive string describing the type of error message. */ - CanteraError(const std::string& procedure, const std::string& msg); + template + CanteraError(const std::string& procedure, const std::string& msg, + const Args&... args) + : procedure_(procedure) + , saved_(false) + { + if (sizeof...(args) == 0) { + msg_ = msg; + } else { + msg_ = fmt::format(msg, args...); + } + // Save the error in the global list of errors so that showError() + // can work + save(); + } //! Destructor for base class does nothing virtual ~CanteraError() throw() {}; diff --git a/src/base/ctexceptions.cpp b/src/base/ctexceptions.cpp index 476d99be0..388c1836b 100644 --- a/src/base/ctexceptions.cpp +++ b/src/base/ctexceptions.cpp @@ -11,15 +11,6 @@ namespace Cantera static const char* stars = "***********************************************************************\n"; -CanteraError::CanteraError(const std::string& procedure, const std::string& msg) : - procedure_(procedure), - msg_(msg), - saved_(false) -{ - // Save the error in the global list of errors so that showError() can work - save(); -} - CanteraError::CanteraError(const std::string& procedure) : procedure_(procedure), saved_(false)