diff options
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/util.cc | 7 | ||||
-rw-r--r-- | src/libutil/util.hh | 14 |
2 files changed, 16 insertions, 5 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index ee34cb18a59e..0d970e69e303 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -25,6 +25,13 @@ Error::Error(const format & f) } +Error & Error::addPrefix(const format & f) +{ + err = f.str() + err; + return *this; +} + + SysError::SysError(const format & f) : Error(format("%1%: %2%") % f.str() % strerror(errno)) { diff --git a/src/libutil/util.hh b/src/libutil/util.hh index aac2acd1730b..05cf777f1eb6 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -26,6 +26,7 @@ public: ~Error() throw () { }; const char * what() const throw () { return err.c_str(); } const string & msg() const throw () { return err; } + Error & addPrefix(const format & f); }; class SysError : public Error @@ -34,11 +35,14 @@ public: SysError(const format & f); }; -class UsageError : public Error -{ -public: - UsageError(const format & f) : Error(f) { }; -}; +#define MakeError(newClass, superClass) \ + class newClass : public superClass \ + { \ + public: \ + newClass(const format & f) : superClass(f) { }; \ + }; + +MakeError(UsageError, Error) typedef list<string> Strings; |