From c8c6ec58a6e23417f9c169af7e1444554140c073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 20 Feb 2019 17:23:37 +0100 Subject: [PATCH] Dynare++: simplify TLException class --- dynare++/tl/cc/tl_exception.hh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/dynare++/tl/cc/tl_exception.hh b/dynare++/tl/cc/tl_exception.hh index b95313f4e..eb14fecb6 100644 --- a/dynare++/tl/cc/tl_exception.hh +++ b/dynare++/tl/cc/tl_exception.hh @@ -12,8 +12,9 @@ #ifndef TL_EXCEPTION_H #define TL_EXCEPTION_H -#include -#include +#include +#include +#include /* The basic idea of raising an exception if some condition fails is that the conditions is checked only if required. We define global @@ -51,22 +52,21 @@ class TLException { - char fname[50]; + const std::string fname; int lnum; - char message[500]; + const std::string message; public: - TLException(const char *f, int l, const char *mes) + TLException(std::string fname_arg, int lnum_arg, std::string message_arg) + : fname{std::move(fname_arg)}, + lnum{lnum_arg}, + message{std::move(message_arg)} { - strncpy(fname, f, 50); fname[49] = '\0'; - strncpy(message, mes, 500); message[499] = '\0'; - lnum = l; } - virtual ~TLException() - = default; + virtual ~TLException() = default; virtual void print() const { - printf("At %s:%d:%s\n", fname, lnum, message); + std::cout << "At " << fname << ':' << lnum << ':' << message << std::endl; } };