Dynare++: simplify TLException class

time-shift
Sébastien Villemot 2019-02-20 17:23:37 +01:00
parent ff57451474
commit c8c6ec58a6
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
1 changed files with 11 additions and 11 deletions

View File

@ -12,8 +12,9 @@
#ifndef TL_EXCEPTION_H #ifndef TL_EXCEPTION_H
#define TL_EXCEPTION_H #define TL_EXCEPTION_H
#include <cstring> #include <iostream>
#include <cstdio> #include <utility>
#include <string>
/* The basic idea of raising an exception if some condition fails is /* The basic idea of raising an exception if some condition fails is
that the conditions is checked only if required. We define global that the conditions is checked only if required. We define global
@ -51,22 +52,21 @@
class TLException class TLException
{ {
char fname[50]; const std::string fname;
int lnum; int lnum;
char message[500]; const std::string message;
public: 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() virtual ~TLException() = default;
= default;
virtual void virtual void
print() const print() const
{ {
printf("At %s:%d:%s\n", fname, lnum, message); std::cout << "At " << fname << ':' << lnum << ':' << message << std::endl;
} }
}; };