diff options
author | Ben Burdette <bburdette@gmail.com> | 2020-04-23 15:55:34 -0600 |
---|---|---|
committer | Ben Burdette <bburdette@gmail.com> | 2020-04-23 15:55:34 -0600 |
commit | 833501f6f11095ae226c13948eb3dc1de2a246ea (patch) | |
tree | 6af8f4fbe0af5897a3504775aa7ca60648e07da5 /src | |
parent | 3bc9155dfc14434f5e9566fd15c79141899f6d07 (diff) |
'what' string
Diffstat (limited to 'src')
-rw-r--r-- | src/libutil/types.hh | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/libutil/types.hh b/src/libutil/types.hh index 2261adb82..141bc6b3c 100644 --- a/src/libutil/types.hh +++ b/src/libutil/types.hh @@ -88,6 +88,13 @@ class BaseError : public std::exception protected: string prefix_; // used for location traces etc. ErrorInfo err; + string what_; + void initWhat() + { + std::ostringstream oss; + oss << err; + what_ = oss.str(); + } public: unsigned int status = 1; // exit status @@ -97,30 +104,27 @@ public: .hint = hintfmt(args...) } , status(status) - { - } + { initWhat(); } template<typename... Args> BaseError(const Args & ... args) : err { .level = lvlError, .hint = hintfmt(args...) } - { - } + { initWhat(); } BaseError(ErrorInfo e) : err(e) - { - } + { initWhat(); } #ifdef EXCEPTION_NEEDS_THROW_SPEC ~BaseError() throw () { }; - const char * what() const throw () { return err.description.c_str(); } + const char * what() const throw () { return what_.c_str(); } #else - const char * what() const noexcept { return err.description.c_str(); } + const char * what() const noexcept { return what_.c_str(); } #endif - const string & msg() const { return err.description; } + const string & msg() const { return what_; } const string & prefix() const { return prefix_; } BaseError & addPrefix(const FormatOrString & fs); |