diff --git a/lemon/error.h b/lemon/error.h --- a/lemon/error.h +++ b/lemon/error.h @@ -41,11 +41,11 @@ /// class Exception : public std::exception { public: - ///\e Constructor - Exception() {} - ///\e Virtual destructor + ///Constructor + Exception() throw() {} + ///Virtual destructor virtual ~Exception() throw() {} - ///\e A short description of the exception + ///A short description of the exception virtual const char* what() const throw() { return "lemon::Exception"; } @@ -64,29 +64,31 @@ public: /// Copy constructor - IoError(const IoError &error) { + IoError(const IoError &error) throw() : Exception() { message(error._message); file(error._file); } /// Constructor - explicit IoError(const char *message) { + explicit IoError(const char *message) throw() { IoError::message(message); } /// Constructor - explicit IoError(const std::string &message) { + explicit IoError(const std::string &message) throw() { IoError::message(message); } /// Constructor - IoError(const std::string &file, const char *message) { + explicit IoError(const char *message, + const std::string &file) throw() { IoError::message(message); IoError::file(file); } /// Constructor - IoError(const std::string &file, const std::string &message) { + explicit IoError(const std::string &message, + const std::string &file) throw() { IoError::message(message); IoError::file(file); } @@ -95,53 +97,50 @@ virtual ~IoError() throw() {} /// Set the error message - void message(const char *message) { + void message(const char *message) throw() { try { _message = message; } catch (...) {} } /// Set the error message - void message(const std::string& message) { + void message(const std::string& message) throw() { try { _message = message; } catch (...) {} } /// Set the file name - void file(const std::string &file) { + void file(const std::string &file) throw() { try { _file = file; } catch (...) {} } /// Returns the error message - const std::string& message() const { + const std::string& message() const throw() { return _message; } /// \brief Returns the filename /// - /// Returns the filename or empty string if the filename was not - /// specified. - const std::string& file() const { + /// Returns the filename or an empty string if it was not specified. + const std::string& file() const throw() { return _file; } /// \brief Returns a short error message /// - /// Returns a short error message which contains the message, the - /// file name and the line number. + /// Returns a short error message which contains the message and the + /// file name. virtual const char* what() const throw() { try { _what.clear(); std::ostringstream oss; oss << "lemon:IoError" << ": "; - oss << message(); - if (!file().empty()) { - oss << " ("; - if (!file().empty()) oss << "with file '" << file() << "'"; - oss << ")"; + oss << _message; + if (!_file.empty()) { + oss << " ('" << _file << "')"; } _what = oss.str(); } @@ -154,8 +153,8 @@ /// \brief Format error /// - /// This class is used to indicate if an input file has wrong - /// formatting, or a data representation is not legal. + /// This exception is thrown when an input file has wrong + /// format or a data representation is not legal. class FormatError : public Exception { protected: std::string _message; @@ -166,33 +165,35 @@ public: /// Copy constructor - FormatError(const FormatError &error) { + FormatError(const FormatError &error) throw() : Exception() { message(error._message); file(error._file); line(error._line); } /// Constructor - explicit FormatError(const char *message) { + explicit FormatError(const char *message) throw() { FormatError::message(message); _line = 0; } /// Constructor - explicit FormatError(const std::string &message) { + explicit FormatError(const std::string &message) throw() { FormatError::message(message); _line = 0; } /// Constructor - FormatError(const std::string &file, int line, const char *message) { + explicit FormatError(const char *message, + const std::string &file, int line = 0) throw() { FormatError::message(message); FormatError::file(file); FormatError::line(line); } /// Constructor - FormatError(const std::string &file, int line, const std::string &message) { + explicit FormatError(const std::string &message, + const std::string &file, int line = 0) throw() { FormatError::message(message); FormatError::file(file); FormatError::line(line); @@ -202,24 +203,24 @@ virtual ~FormatError() throw() {} /// Set the line number - void line(int line) { _line = line; } + void line(int line) throw() { _line = line; } /// Set the error message - void message(const char *message) { + void message(const char *message) throw() { try { _message = message; } catch (...) {} } /// Set the error message - void message(const std::string& message) { + void message(const std::string& message) throw() { try { _message = message; } catch (...) {} } /// Set the file name - void file(const std::string &file) { + void file(const std::string &file) throw() { try { _file = file; } catch (...) {} @@ -228,18 +229,17 @@ /// \brief Returns the line number /// /// Returns the line number or zero if it was not specified. - int line() const { return _line; } + int line() const throw() { return _line; } /// Returns the error message - const std::string& message() const { + const std::string& message() const throw() { return _message; } /// \brief Returns the filename /// - /// Returns the filename or empty string if the filename was not - /// specified. - const std::string& file() const { + /// Returns the filename or an empty string if it was not specified. + const std::string& file() const throw() { return _file; } @@ -252,12 +252,12 @@ _what.clear(); std::ostringstream oss; oss << "lemon:FormatError" << ": "; - oss << message(); - if (!file().empty() || line() != 0) { + oss << _message; + if (!_file.empty() || _line != 0) { oss << " ("; - if (!file().empty()) oss << "in file '" << file() << "'"; - if (!file().empty() && line() != 0) oss << " "; - if (line() != 0) oss << "at line " << line(); + if (!_file.empty()) oss << "in file '" << _file << "'"; + if (!_file.empty() && _line != 0) oss << " "; + if (_line != 0) oss << "at line " << _line; oss << ")"; } _what = oss.str();