1.1 --- a/src/work/klao/error.h Fri Jan 07 18:53:02 2005 +0000
1.2 +++ b/src/work/klao/error.h Sat Jan 08 20:12:50 2005 +0000
1.3 @@ -32,8 +32,10 @@
1.4 /// Exception-safe convenient "error message" class.
1.5 class ErrorMessage {
1.6 protected:
1.7 + ///\e
1.8 boost::shared_ptr<std::ostringstream> buf;
1.9
1.10 + ///\e
1.11 bool init() throw() {
1.12 try {
1.13 buf.reset(new std::ostringstream);
1.14 @@ -46,18 +48,22 @@
1.15
1.16 public:
1.17
1.18 + ///\e
1.19 ErrorMessage() throw() { init(); }
1.20
1.21 + ///\e
1.22 ErrorMessage(const char *message) throw() {
1.23 init();
1.24 *this << message;
1.25 }
1.26
1.27 + ///\e
1.28 ErrorMessage(const std::string &message) throw() {
1.29 init();
1.30 *this << message;
1.31 }
1.32
1.33 + ///\e
1.34 template <typename T>
1.35 ErrorMessage& operator<<(const T &t) throw() {
1.36 if( !buf ) return *this;
1.37 @@ -70,6 +76,7 @@
1.38 }
1.39 }
1.40
1.41 + ///\e
1.42 const char* message() throw() {
1.43 if( !buf ) return 0;
1.44
1.45 @@ -90,11 +97,15 @@
1.46 */
1.47 class Exception : public std::exception, public ErrorMessage {
1.48 public:
1.49 + ///\e
1.50 Exception() throw() {}
1.51 + ///\e
1.52 explicit Exception(const std::string &s) throw()
1.53 : ErrorMessage(s) {}
1.54 + ///\e
1.55 virtual ~Exception() throw() {}
1.56
1.57 + ///\e
1.58 virtual const char* what() const throw() {
1.59 const char *mes = message();
1.60 if( mes ) return mes;
1.61 @@ -102,35 +113,47 @@
1.62 }
1.63 };
1.64
1.65 -
1.66 + ///\e
1.67 class LogicError : public Exception {
1.68 + ///\e
1.69 explicit LogicError(const std::string &s)
1.70 : Exception(s) {}
1.71 };
1.72
1.73 + ///\e
1.74 class RuntimeError : public Exception {
1.75 + ///\e
1.76 explicit RuntimeError(const std::string &s)
1.77 : Exception(s) {}
1.78 };
1.79
1.80 + ///\e
1.81 class RangeError : public RuntimeError {
1.82 + ///\e
1.83 explicit RangeError(const std::string &s)
1.84 : RuntimeError(s) {}
1.85 };
1.86
1.87 + ///\e
1.88 class IOError : public RuntimeError {
1.89 + ///\e
1.90 explicit IOError(const std::string &s)
1.91 : RuntimeError(s) {}
1.92 };
1.93
1.94 + ///\e
1.95 class DataFormatError : public IOError {
1.96 + ///\e
1.97 explicit DataFormatError(const std::string &message)
1.98 : IOError(message) : line(0) {}
1.99 + ///\e
1.100 DataFormatError(const std::string &file_name, int line_num,
1.101 - sconst std::string &message)
1.102 + const std::string &message)
1.103 : IOError(message), line(line_num) { set_file(file_name); }
1.104
1.105 + ///\e
1.106 void set_line(int line_num) { line=line_num; }
1.107 + ///\e
1.108 void set_file(const std::string &file_name) {
1.109 try {
1.110 file.reset(new std::string);
1.111 @@ -141,6 +164,7 @@
1.112 }
1.113 }
1.114
1.115 + ///\e
1.116 virtual const char* what() const {
1.117 const char *mes = 0;
1.118 try {