COIN-OR::LEMON - Graph Library

Changeset 291:d901321d6555 in lemon-main for lemon/error.h


Ignore:
Timestamp:
10/01/08 11:58:03 (16 years ago)
Author:
Peter Kovacs <kpeter@…>
Branch:
default
Phase:
public
Message:

Changing parameter order in exception classes + improvements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/error.h

    r290 r291  
    4242  class Exception : public std::exception {
    4343  public:
    44     ///\e Constructor
    45     Exception() {}
    46     ///\e Virtual destructor
     44    ///Constructor
     45    Exception() throw() {}
     46    ///Virtual destructor
    4747    virtual ~Exception() throw() {}
    48     ///\e A short description of the exception
     48    ///A short description of the exception
    4949    virtual const char* what() const throw() {
    5050      return "lemon::Exception";
     
    6565
    6666    /// Copy constructor
    67     IoError(const IoError &error) {
     67    IoError(const IoError &error) throw() : Exception() {
    6868      message(error._message);
    6969      file(error._file);
     
    7171
    7272    /// Constructor
    73     explicit IoError(const char *message) {
    74       IoError::message(message);
    75     }
    76 
    77     /// Constructor
    78     explicit IoError(const std::string &message) {
    79       IoError::message(message);
    80     }
    81 
    82     /// Constructor
    83     IoError(const std::string &file, const char *message) {
     73    explicit IoError(const char *message) throw() {
     74      IoError::message(message);
     75    }
     76
     77    /// Constructor
     78    explicit IoError(const std::string &message) throw() {
     79      IoError::message(message);
     80    }
     81
     82    /// Constructor
     83    explicit IoError(const char *message,
     84                     const std::string &file) throw() {
    8485      IoError::message(message);
    8586      IoError::file(file);
     
    8788
    8889    /// Constructor
    89     IoError(const std::string &file, const std::string &message) {
     90    explicit IoError(const std::string &message,
     91                     const std::string &file) throw() {
    9092      IoError::message(message);
    9193      IoError::file(file);
     
    9698
    9799    /// Set the error message
    98     void message(const char *message) {
    99       try {
    100         _message = message;
    101       } catch (...) {}
    102     }
    103 
    104     /// Set the error message
    105     void message(const std::string& message) {
     100    void message(const char *message) throw() {
     101      try {
     102        _message = message;
     103      } catch (...) {}
     104    }
     105
     106    /// Set the error message
     107    void message(const std::string& message) throw() {
    106108      try {
    107109        _message = message;
     
    110112
    111113    /// Set the file name
    112     void file(const std::string &file) {
     114    void file(const std::string &file) throw() {
    113115      try {
    114116        _file = file;
     
    117119
    118120    /// Returns the error message
    119     const std::string& message() const {
     121    const std::string& message() const throw() {
    120122      return _message;
    121123    }
     
    123125    /// \brief Returns the filename
    124126    ///
    125     /// Returns the filename or empty string if the filename was not
    126     /// specified.
    127     const std::string& file() const {
     127    /// Returns the filename or an empty string if it was not specified.
     128    const std::string& file() const throw() {
    128129      return _file;
    129130    }
     
    131132    /// \brief Returns a short error message
    132133    ///
    133     /// Returns a short error message which contains the message, the
    134     /// file name and the line number.
     134    /// Returns a short error message which contains the message and the
     135    /// file name.
    135136    virtual const char* what() const throw() {
    136137      try {
     
    138139        std::ostringstream oss;
    139140        oss << "lemon:IoError" << ": ";
    140         oss << message();
    141         if (!file().empty()) {
    142           oss << " (";
    143           if (!file().empty()) oss << "with file '" << file() << "'";
    144           oss << ")";
     141        oss << _message;
     142        if (!_file.empty()) {
     143          oss << " ('" << _file << "')";
    145144        }
    146145        _what = oss.str();
     
    155154  /// \brief Format error
    156155  ///
    157   /// This class is used to indicate if an input file has wrong
    158   /// formatting, or a data representation is not legal.
     156  /// This exception is thrown when an input file has wrong
     157  /// format or a data representation is not legal.
    159158  class FormatError : public Exception {
    160159  protected:
     
    167166
    168167    /// Copy constructor
    169     FormatError(const FormatError &error) {
     168    FormatError(const FormatError &error) throw() : Exception() {
    170169      message(error._message);
    171170      file(error._file);
     
    174173
    175174    /// Constructor
    176     explicit FormatError(const char *message) {
     175    explicit FormatError(const char *message) throw() {
    177176      FormatError::message(message);
    178177      _line = 0;
     
    180179
    181180    /// Constructor
    182     explicit FormatError(const std::string &message) {
     181    explicit FormatError(const std::string &message) throw() {
    183182      FormatError::message(message);
    184183      _line = 0;
     
    186185
    187186    /// Constructor
    188     FormatError(const std::string &file, int line, const char *message) {
     187    explicit FormatError(const char *message,
     188                         const std::string &file, int line = 0) throw() {
    189189      FormatError::message(message);
    190190      FormatError::file(file);
     
    193193
    194194    /// Constructor
    195     FormatError(const std::string &file, int line, const std::string &message) {
     195    explicit FormatError(const std::string &message,
     196                         const std::string &file, int line = 0) throw() {
    196197      FormatError::message(message);
    197198      FormatError::file(file);
     
    203204
    204205    /// Set the line number
    205     void line(int line) { _line = line; }
    206 
    207     /// Set the error message
    208     void message(const char *message) {
    209       try {
    210         _message = message;
    211       } catch (...) {}
    212     }
    213 
    214     /// Set the error message
    215     void message(const std::string& message) {
     206    void line(int line) throw() { _line = line; }
     207
     208    /// Set the error message
     209    void message(const char *message) throw() {
     210      try {
     211        _message = message;
     212      } catch (...) {}
     213    }
     214
     215    /// Set the error message
     216    void message(const std::string& message) throw() {
    216217      try {
    217218        _message = message;
     
    220221
    221222    /// Set the file name
    222     void file(const std::string &file) {
     223    void file(const std::string &file) throw() {
    223224      try {
    224225        _file = file;
     
    229230    ///
    230231    /// Returns the line number or zero if it was not specified.
    231     int line() const { return _line; }
     232    int line() const throw() { return _line; }
    232233
    233234    /// Returns the error message
    234     const std::string& message() const {
     235    const std::string& message() const throw() {
    235236      return _message;
    236237    }
     
    238239    /// \brief Returns the filename
    239240    ///
    240     /// Returns the filename or empty string if the filename was not
    241     /// specified.
    242     const std::string& file() const {
     241    /// Returns the filename or an empty string if it was not specified.
     242    const std::string& file() const throw() {
    243243      return _file;
    244244    }
     
    253253        std::ostringstream oss;
    254254        oss << "lemon:FormatError" << ": ";
    255         oss << message();
    256         if (!file().empty() || line() != 0) {
     255        oss << _message;
     256        if (!_file.empty() || _line != 0) {
    257257          oss << " (";
    258           if (!file().empty()) oss << "in file '" << file() << "'";
    259           if (!file().empty() && line() != 0) oss << " ";
    260           if (line() != 0) oss << "at line " << line();
     258          if (!_file.empty()) oss << "in file '" << _file << "'";
     259          if (!_file.empty() && _line != 0) oss << " ";
     260          if (_line != 0) oss << "at line " << _line;
    261261          oss << ")";
    262262        }
Note: See TracChangeset for help on using the changeset viewer.