diff -r 7a24bb2e7480 -r e3433c024123 src/work/klao/error.h --- a/src/work/klao/error.h Fri Jan 07 18:53:02 2005 +0000 +++ b/src/work/klao/error.h Sat Jan 08 20:12:50 2005 +0000 @@ -32,8 +32,10 @@ /// Exception-safe convenient "error message" class. class ErrorMessage { protected: + ///\e boost::shared_ptr buf; + ///\e bool init() throw() { try { buf.reset(new std::ostringstream); @@ -46,18 +48,22 @@ public: + ///\e ErrorMessage() throw() { init(); } + ///\e ErrorMessage(const char *message) throw() { init(); *this << message; } + ///\e ErrorMessage(const std::string &message) throw() { init(); *this << message; } + ///\e template ErrorMessage& operator<<(const T &t) throw() { if( !buf ) return *this; @@ -70,6 +76,7 @@ } } + ///\e const char* message() throw() { if( !buf ) return 0; @@ -90,11 +97,15 @@ */ class Exception : public std::exception, public ErrorMessage { public: + ///\e Exception() throw() {} + ///\e explicit Exception(const std::string &s) throw() : ErrorMessage(s) {} + ///\e virtual ~Exception() throw() {} + ///\e virtual const char* what() const throw() { const char *mes = message(); if( mes ) return mes; @@ -102,35 +113,47 @@ } }; - + ///\e class LogicError : public Exception { + ///\e explicit LogicError(const std::string &s) : Exception(s) {} }; + ///\e class RuntimeError : public Exception { + ///\e explicit RuntimeError(const std::string &s) : Exception(s) {} }; + ///\e class RangeError : public RuntimeError { + ///\e explicit RangeError(const std::string &s) : RuntimeError(s) {} }; + ///\e class IOError : public RuntimeError { + ///\e explicit IOError(const std::string &s) : RuntimeError(s) {} }; + ///\e class DataFormatError : public IOError { + ///\e explicit DataFormatError(const std::string &message) : IOError(message) : line(0) {} + ///\e DataFormatError(const std::string &file_name, int line_num, - sconst std::string &message) + const std::string &message) : IOError(message), line(line_num) { set_file(file_name); } + ///\e void set_line(int line_num) { line=line_num; } + ///\e void set_file(const std::string &file_name) { try { file.reset(new std::string); @@ -141,6 +164,7 @@ } } + ///\e virtual const char* what() const { const char *mes = 0; try {