1.1 --- a/lemon/error.h Tue Sep 30 20:53:18 2008 +0200
1.2 +++ b/lemon/error.h Wed Oct 01 11:58:03 2008 +0200
1.3 @@ -41,11 +41,11 @@
1.4 ///
1.5 class Exception : public std::exception {
1.6 public:
1.7 - ///\e Constructor
1.8 - Exception() {}
1.9 - ///\e Virtual destructor
1.10 + ///Constructor
1.11 + Exception() throw() {}
1.12 + ///Virtual destructor
1.13 virtual ~Exception() throw() {}
1.14 - ///\e A short description of the exception
1.15 + ///A short description of the exception
1.16 virtual const char* what() const throw() {
1.17 return "lemon::Exception";
1.18 }
1.19 @@ -64,29 +64,31 @@
1.20 public:
1.21
1.22 /// Copy constructor
1.23 - IoError(const IoError &error) {
1.24 + IoError(const IoError &error) throw() : Exception() {
1.25 message(error._message);
1.26 file(error._file);
1.27 }
1.28
1.29 /// Constructor
1.30 - explicit IoError(const char *message) {
1.31 + explicit IoError(const char *message) throw() {
1.32 IoError::message(message);
1.33 }
1.34
1.35 /// Constructor
1.36 - explicit IoError(const std::string &message) {
1.37 + explicit IoError(const std::string &message) throw() {
1.38 IoError::message(message);
1.39 }
1.40
1.41 /// Constructor
1.42 - IoError(const std::string &file, const char *message) {
1.43 + explicit IoError(const char *message,
1.44 + const std::string &file) throw() {
1.45 IoError::message(message);
1.46 IoError::file(file);
1.47 }
1.48
1.49 /// Constructor
1.50 - IoError(const std::string &file, const std::string &message) {
1.51 + explicit IoError(const std::string &message,
1.52 + const std::string &file) throw() {
1.53 IoError::message(message);
1.54 IoError::file(file);
1.55 }
1.56 @@ -95,53 +97,50 @@
1.57 virtual ~IoError() throw() {}
1.58
1.59 /// Set the error message
1.60 - void message(const char *message) {
1.61 + void message(const char *message) throw() {
1.62 try {
1.63 _message = message;
1.64 } catch (...) {}
1.65 }
1.66
1.67 /// Set the error message
1.68 - void message(const std::string& message) {
1.69 + void message(const std::string& message) throw() {
1.70 try {
1.71 _message = message;
1.72 } catch (...) {}
1.73 }
1.74
1.75 /// Set the file name
1.76 - void file(const std::string &file) {
1.77 + void file(const std::string &file) throw() {
1.78 try {
1.79 _file = file;
1.80 } catch (...) {}
1.81 }
1.82
1.83 /// Returns the error message
1.84 - const std::string& message() const {
1.85 + const std::string& message() const throw() {
1.86 return _message;
1.87 }
1.88
1.89 /// \brief Returns the filename
1.90 ///
1.91 - /// Returns the filename or empty string if the filename was not
1.92 - /// specified.
1.93 - const std::string& file() const {
1.94 + /// Returns the filename or an empty string if it was not specified.
1.95 + const std::string& file() const throw() {
1.96 return _file;
1.97 }
1.98
1.99 /// \brief Returns a short error message
1.100 ///
1.101 - /// Returns a short error message which contains the message, the
1.102 - /// file name and the line number.
1.103 + /// Returns a short error message which contains the message and the
1.104 + /// file name.
1.105 virtual const char* what() const throw() {
1.106 try {
1.107 _what.clear();
1.108 std::ostringstream oss;
1.109 oss << "lemon:IoError" << ": ";
1.110 - oss << message();
1.111 - if (!file().empty()) {
1.112 - oss << " (";
1.113 - if (!file().empty()) oss << "with file '" << file() << "'";
1.114 - oss << ")";
1.115 + oss << _message;
1.116 + if (!_file.empty()) {
1.117 + oss << " ('" << _file << "')";
1.118 }
1.119 _what = oss.str();
1.120 }
1.121 @@ -154,8 +153,8 @@
1.122
1.123 /// \brief Format error
1.124 ///
1.125 - /// This class is used to indicate if an input file has wrong
1.126 - /// formatting, or a data representation is not legal.
1.127 + /// This exception is thrown when an input file has wrong
1.128 + /// format or a data representation is not legal.
1.129 class FormatError : public Exception {
1.130 protected:
1.131 std::string _message;
1.132 @@ -166,33 +165,35 @@
1.133 public:
1.134
1.135 /// Copy constructor
1.136 - FormatError(const FormatError &error) {
1.137 + FormatError(const FormatError &error) throw() : Exception() {
1.138 message(error._message);
1.139 file(error._file);
1.140 line(error._line);
1.141 }
1.142
1.143 /// Constructor
1.144 - explicit FormatError(const char *message) {
1.145 + explicit FormatError(const char *message) throw() {
1.146 FormatError::message(message);
1.147 _line = 0;
1.148 }
1.149
1.150 /// Constructor
1.151 - explicit FormatError(const std::string &message) {
1.152 + explicit FormatError(const std::string &message) throw() {
1.153 FormatError::message(message);
1.154 _line = 0;
1.155 }
1.156
1.157 /// Constructor
1.158 - FormatError(const std::string &file, int line, const char *message) {
1.159 + explicit FormatError(const char *message,
1.160 + const std::string &file, int line = 0) throw() {
1.161 FormatError::message(message);
1.162 FormatError::file(file);
1.163 FormatError::line(line);
1.164 }
1.165
1.166 /// Constructor
1.167 - FormatError(const std::string &file, int line, const std::string &message) {
1.168 + explicit FormatError(const std::string &message,
1.169 + const std::string &file, int line = 0) throw() {
1.170 FormatError::message(message);
1.171 FormatError::file(file);
1.172 FormatError::line(line);
1.173 @@ -202,24 +203,24 @@
1.174 virtual ~FormatError() throw() {}
1.175
1.176 /// Set the line number
1.177 - void line(int line) { _line = line; }
1.178 + void line(int line) throw() { _line = line; }
1.179
1.180 /// Set the error message
1.181 - void message(const char *message) {
1.182 + void message(const char *message) throw() {
1.183 try {
1.184 _message = message;
1.185 } catch (...) {}
1.186 }
1.187
1.188 /// Set the error message
1.189 - void message(const std::string& message) {
1.190 + void message(const std::string& message) throw() {
1.191 try {
1.192 _message = message;
1.193 } catch (...) {}
1.194 }
1.195
1.196 /// Set the file name
1.197 - void file(const std::string &file) {
1.198 + void file(const std::string &file) throw() {
1.199 try {
1.200 _file = file;
1.201 } catch (...) {}
1.202 @@ -228,18 +229,17 @@
1.203 /// \brief Returns the line number
1.204 ///
1.205 /// Returns the line number or zero if it was not specified.
1.206 - int line() const { return _line; }
1.207 + int line() const throw() { return _line; }
1.208
1.209 /// Returns the error message
1.210 - const std::string& message() const {
1.211 + const std::string& message() const throw() {
1.212 return _message;
1.213 }
1.214
1.215 /// \brief Returns the filename
1.216 ///
1.217 - /// Returns the filename or empty string if the filename was not
1.218 - /// specified.
1.219 - const std::string& file() const {
1.220 + /// Returns the filename or an empty string if it was not specified.
1.221 + const std::string& file() const throw() {
1.222 return _file;
1.223 }
1.224
1.225 @@ -252,12 +252,12 @@
1.226 _what.clear();
1.227 std::ostringstream oss;
1.228 oss << "lemon:FormatError" << ": ";
1.229 - oss << message();
1.230 - if (!file().empty() || line() != 0) {
1.231 + oss << _message;
1.232 + if (!_file.empty() || _line != 0) {
1.233 oss << " (";
1.234 - if (!file().empty()) oss << "in file '" << file() << "'";
1.235 - if (!file().empty() && line() != 0) oss << " ";
1.236 - if (line() != 0) oss << "at line " << line();
1.237 + if (!_file.empty()) oss << "in file '" << _file << "'";
1.238 + if (!_file.empty() && _line != 0) oss << " ";
1.239 + if (_line != 0) oss << "at line " << _line;
1.240 oss << ")";
1.241 }
1.242 _what = oss.str();