COIN-OR::LEMON - Graph Library

Changes in / [292:e7af73f1805e:289:d91884dcd572] in lemon-1.0


Ignore:
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • demo/lgf_demo.cc

    r290 r209  
    5050      node("target", t).             // read 'target' node to t
    5151      run();
    52   } catch (Exception& error) { // check if there was any error
     52  } catch (DataFormatError& error) { // check if there was any error
    5353    std::cerr << "Error: " << error.what() << std::endl;
    5454    return -1;
  • lemon/arg_parser.h

    r290 r261  
    311311    ///This is the type of the return value of ArgParser::operator[]().
    312312    ///It automatically converts to \c int, \c double, \c bool or
    313     ///\c std::string if the type of the option matches, which is checked
    314     ///with an \ref LEMON_ASSERT "assertion" (i.e. it performs runtime
    315     ///type checking).
     313    ///\c std::string if the type of the option matches, otherwise it
     314    ///throws an exception (i.e. it performs runtime type checking).
    316315    class RefType
    317316    {
  • lemon/assert.h

    r290 r277  
    109109/// \brief Macro for assertion with customizable message
    110110///
    111 /// Macro for assertion with customizable message.
     111/// Macro for assertion with customizable message. 
    112112/// \param exp An expression that must be convertible to \c bool.  If it is \c
    113113/// false, then an assertion is raised. The concrete behaviour depends on the
  • lemon/bfs.h

    r292 r288  
    136136  class Bfs {
    137137  public:
     138    ///\ref Exception for uninitialized parameters.
     139
     140    ///This error represents problems in the initialization of the
     141    ///parameters of the algorithm.
     142    class UninitializedParameter : public lemon::UninitializedParameter {
     143    public:
     144      virtual const char* what() const throw() {
     145        return "lemon::Bfs::UninitializedParameter";
     146      }
     147    };
    138148
    139149    ///The type of the digraph the algorithm runs on.
     
    223233      static PredMap *createPredMap(const Digraph &)
    224234      {
    225         LEMON_ASSERT(false, "PredMap is not initialized");
    226         return 0; // ignore warnings
     235        throw UninitializedParameter();
    227236      }
    228237    };
     
    242251      static DistMap *createDistMap(const Digraph &)
    243252      {
    244         LEMON_ASSERT(false, "DistMap is not initialized");
    245         return 0; // ignore warnings
     253        throw UninitializedParameter();
    246254      }
    247255    };
     
    261269      static ReachedMap *createReachedMap(const Digraph &)
    262270      {
    263         LEMON_ASSERT(false, "ReachedMap is not initialized");
    264         return 0; // ignore warnings
     271        throw UninitializedParameter();
    265272      }
    266273    };
     
    280287      static ProcessedMap *createProcessedMap(const Digraph &)
    281288      {
    282         LEMON_ASSERT(false, "ProcessedMap is not initialized");
    283         return 0; // ignore warnings
     289        throw UninitializedParameter();
    284290      }
    285291    };
     
    299305      {
    300306        return new ProcessedMap(g);
    301         return 0; // ignore warnings
    302307      }
    303308    };
     
    10361041    bool run(Node s, Node t)
    10371042    {
     1043      if (s==INVALID || t==INVALID) throw UninitializedParameter();
    10381044      Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
    10391045      if (Base::_pred)
     
    13181324  public:
    13191325
     1326    /// \brief \ref Exception for uninitialized parameters.
     1327    ///
     1328    /// This error represents problems in the initialization
     1329    /// of the parameters of the algorithm.
     1330    class UninitializedParameter : public lemon::UninitializedParameter {
     1331    public:
     1332      virtual const char* what() const throw()
     1333      {
     1334        return "lemon::BfsVisit::UninitializedParameter";
     1335      }
     1336    };
     1337
    13201338    ///The traits class.
    13211339    typedef _Traits Traits;
     
    13721390      typedef T ReachedMap;
    13731391      static ReachedMap *createReachedMap(const Digraph &digraph) {
    1374         LEMON_ASSERT(false, "ReachedMap is not initialized");
    1375         return 0; // ignore warnings
     1392        throw UninitializedParameter();
    13761393      }
    13771394    };
  • lemon/concepts/heap.h

    r290 r220  
    130130      /// Otherwise it inserts the given item with the given priority.
    131131      ///
     132      /// It may throw an \ref UnderflowPriorityException.
    132133      /// \param i The item.
    133134      /// \param p The priority.
  • lemon/dfs.h

    r292 r288  
    137137  class Dfs {
    138138  public:
     139    ///\ref Exception for uninitialized parameters.
     140
     141    ///This error represents problems in the initialization of the
     142    ///parameters of the algorithm.
     143    class UninitializedParameter : public lemon::UninitializedParameter {
     144    public:
     145      virtual const char* what() const throw() {
     146        return "lemon::Dfs::UninitializedParameter";
     147      }
     148    };
    139149
    140150    ///The type of the digraph the algorithm runs on.
     
    223233      static PredMap *createPredMap(const Digraph &)
    224234      {
    225         LEMON_ASSERT(false, "PredMap is not initialized");
    226         return 0; // ignore warnings
     235        throw UninitializedParameter();
    227236      }
    228237    };
     
    242251      static DistMap *createDistMap(const Digraph &)
    243252      {
    244         LEMON_ASSERT(false, "DistMap is not initialized");
    245         return 0; // ignore warnings
     253        throw UninitializedParameter();
    246254      }
    247255    };
     
    261269      static ReachedMap *createReachedMap(const Digraph &)
    262270      {
    263         LEMON_ASSERT(false, "ReachedMap is not initialized");
    264         return 0; // ignore warnings
     271        throw UninitializedParameter();
    265272      }
    266273    };
     
    280287      static ProcessedMap *createProcessedMap(const Digraph &)
    281288      {
    282         LEMON_ASSERT(false, "ProcessedMap is not initialized");
    283         return 0; // ignore warnings
     289        throw UninitializedParameter();
    284290      }
    285291    };
     
    969975    bool run(Node s, Node t)
    970976    {
     977      if (s==INVALID || t==INVALID) throw UninitializedParameter();
    971978      Dfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
    972979      if (Base::_pred)
     
    12641271  public:
    12651272
     1273    /// \brief \ref Exception for uninitialized parameters.
     1274    ///
     1275    /// This error represents problems in the initialization
     1276    /// of the parameters of the algorithm.
     1277    class UninitializedParameter : public lemon::UninitializedParameter {
     1278    public:
     1279      virtual const char* what() const throw()
     1280      {
     1281        return "lemon::DfsVisit::UninitializedParameter";
     1282      }
     1283    };
     1284
    12661285    ///The traits class.
    12671286    typedef _Traits Traits;
     
    13181337      typedef T ReachedMap;
    13191338      static ReachedMap *createReachedMap(const Digraph &digraph) {
    1320         LEMON_ASSERT(false, "ReachedMap is not initialized");
    1321         return 0; // ignore warnings
     1339        throw UninitializedParameter();
    13221340      }
    13231341    };
  • lemon/dijkstra.h

    r290 r287  
    226226  class Dijkstra {
    227227  public:
     228    ///\ref Exception for uninitialized parameters.
     229
     230    ///This error represents problems in the initialization of the
     231    ///parameters of the algorithm.
     232    class UninitializedParameter : public lemon::UninitializedParameter {
     233    public:
     234      virtual const char* what() const throw() {
     235        return "lemon::Dijkstra::UninitializedParameter";
     236      }
     237    };
    228238
    229239    ///The type of the digraph the algorithm runs on.
     
    323333      static PredMap *createPredMap(const Digraph &)
    324334      {
    325         LEMON_ASSERT(false, "PredMap is not initialized");
    326         return 0; // ignore warnings
     335        throw UninitializedParameter();
    327336      }
    328337    };
     
    343352      static DistMap *createDistMap(const Digraph &)
    344353      {
    345         LEMON_ASSERT(false, "DistMap is not initialized");
    346         return 0; // ignore warnings
     354        throw UninitializedParameter();
    347355      }
    348356    };
     
    363371      static ProcessedMap *createProcessedMap(const Digraph &)
    364372      {
    365         LEMON_ASSERT(false, "ProcessedMap is not initialized");
    366         return 0; // ignore warnings
     373        throw UninitializedParameter();
    367374      }
    368375    };
     
    402409      typedef H Heap;
    403410      static HeapCrossRef *createHeapCrossRef(const Digraph &) {
    404         LEMON_ASSERT(false, "HeapCrossRef is not initialized");
    405         return 0; // ignore warnings
     411        throw UninitializedParameter();
    406412      }
    407413      static Heap *createHeap(HeapCrossRef &)
    408414      {
    409         LEMON_ASSERT(false, "Heap is not initialized");
    410         return 0; // ignore warnings
     415        throw UninitializedParameter();
    411416      }
    412417    };
     
    11541159    void run(Node s)
    11551160    {
     1161      if (s==INVALID) throw UninitializedParameter();
    11561162      Dijkstra<Digraph,LengthMap,TR>
    11571163        dijk(*reinterpret_cast<const Digraph*>(Base::_g),
     
    11751181    bool run(Node s, Node t)
    11761182    {
     1183      if (s==INVALID || t==INVALID) throw UninitializedParameter();
    11771184      Dijkstra<Digraph,LengthMap,TR>
    11781185        dijk(*reinterpret_cast<const Digraph*>(Base::_g),
  • lemon/error.h

    r291 r280  
    3636  /// @{
    3737
    38   /// \brief Generic exception class.
     38  /// \brief Exception safe wrapper class.
    3939  ///
     40  /// Exception safe wrapper class to implement the members of exceptions.
     41  template <typename _Type>
     42  class ExceptionMember {
     43  public:
     44    typedef _Type Type;
     45
     46    ExceptionMember() throw() {
     47      try {
     48        ptr.reset(new Type());
     49      } catch (...) {}
     50    }
     51
     52    ExceptionMember(const Type& type) throw() {
     53      try {
     54        ptr.reset(new Type());
     55        if (ptr.get() == 0) return;
     56        *ptr = type;
     57      } catch (...) {}
     58    }
     59
     60    ExceptionMember(const ExceptionMember& copy) throw() {
     61      try {
     62        if (!copy.valid()) return;
     63        ptr.reset(new Type());
     64        if (ptr.get() == 0) return;
     65        *ptr = copy.get();
     66      } catch (...) {}
     67    }
     68
     69    ExceptionMember& operator=(const ExceptionMember& copy) throw() {
     70      if (ptr.get() == 0) return;
     71      try {
     72        if (!copy.valid()) return;
     73        *ptr = copy.get();
     74      } catch (...) {}
     75    }
     76
     77    void set(const Type& type) throw() {
     78      if (ptr.get() == 0) return;
     79      try {
     80        *ptr = type;
     81      } catch (...) {}
     82    }
     83
     84    const Type& get() const {
     85      return *ptr;
     86    }
     87
     88    bool valid() const throw() {
     89      return ptr.get() != 0;
     90    }
     91
     92  private:
     93    std::auto_ptr<_Type> ptr;
     94  };
     95
     96  /// Exception-safe convenient error message builder class.
     97
     98  /// Helper class which provides a convenient ostream-like (operator <<
     99  /// based) interface to create a string message. Mostly useful in
     100  /// exception classes (therefore the name).
     101  class ErrorMessage {
     102  protected:
     103    ///\e
     104
     105    mutable std::auto_ptr<std::ostringstream> buf;
     106
     107    ///\e
     108    bool init() throw() {
     109      try {
     110        buf.reset(new std::ostringstream);
     111      }
     112      catch(...) {
     113        buf.reset();
     114      }
     115      return buf.get();
     116    }
     117
     118  public:
     119
     120    ///\e
     121    ErrorMessage() throw() { init(); }
     122
     123    ErrorMessage(const ErrorMessage& em) throw() : buf(em.buf) { }
     124
     125    ///\e
     126    ErrorMessage(const char *msg) throw() {
     127      init();
     128      *this << msg;
     129    }
     130
     131    ///\e
     132    ErrorMessage(const std::string &msg) throw() {
     133      init();
     134      *this << msg;
     135    }
     136
     137    ///\e
     138    template <typename T>
     139    ErrorMessage& operator<<(const T &t) throw() {
     140      if( ! buf.get() ) return *this;
     141
     142      try {
     143        *buf << t;
     144      }
     145      catch(...) {
     146        buf.reset();
     147      }
     148      return *this;
     149    }
     150
     151    ///\e
     152    const char* message() throw() {
     153      if( ! buf.get() ) return 0;
     154
     155      const char* mes = 0;
     156      try {
     157        mes = buf->str().c_str();
     158      }
     159      catch(...) {}
     160      return mes;
     161    }
     162
     163  };
     164
     165  /// Generic exception class.
     166
    40167  /// Base class for exceptions used in LEMON.
    41168  ///
    42169  class Exception : public std::exception {
    43170  public:
    44     ///Constructor
    45     Exception() throw() {}
    46     ///Virtual destructor
     171    ///\e
     172    Exception() {}
     173    ///\e
    47174    virtual ~Exception() throw() {}
    48     ///A short description of the exception
     175    ///\e
    49176    virtual const char* what() const throw() {
    50177      return "lemon::Exception";
     
    52179  };
    53180
    54   /// \brief Input-Output error
     181  /// One of the two main subclasses of \ref Exception.
     182
     183  /// Logic errors represent problems in the internal logic of a program;
     184  /// in theory, these are preventable, and even detectable before the
     185  /// program runs (e.g. violations of class invariants).
    55186  ///
    56   /// This exception is thrown when a file operation cannot be
    57   /// succeeded.
    58   class IoError : public Exception {
     187  /// A typical example for this is \ref UninitializedParameter.
     188  class LogicError : public Exception {
     189  public:
     190    virtual const char* what() const throw() {
     191      return "lemon::LogicError";
     192    }
     193  };
     194
     195  /// \ref Exception for uninitialized parameters.
     196
     197  /// This error represents problems in the initialization
     198  /// of the parameters of the algorithms.
     199  class UninitializedParameter : public LogicError {
     200  public:
     201    virtual const char* what() const throw() {
     202      return "lemon::UninitializedParameter";
     203    }
     204  };
     205
     206
     207  /// One of the two main subclasses of \ref Exception.
     208
     209  /// Runtime errors represent problems outside the scope of a program;
     210  /// they cannot be easily predicted and can generally only be caught
     211  /// as the program executes.
     212  class RuntimeError : public Exception {
     213  public:
     214    virtual const char* what() const throw() {
     215      return "lemon::RuntimeError";
     216    }
     217  };
     218
     219  ///\e
     220  class RangeError : public RuntimeError {
     221  public:
     222    virtual const char* what() const throw() {
     223      return "lemon::RangeError";
     224    }
     225  };
     226
     227  ///\e
     228  class IoError : public RuntimeError {
     229  public:
     230    virtual const char* what() const throw() {
     231      return "lemon::IoError";
     232    }
     233  };
     234
     235  ///\e
     236  class DataFormatError : public IoError {
    59237  protected:
    60     std::string _message;
    61     std::string _file;
    62 
    63     mutable std::string _what;
    64   public:
    65 
    66     /// Copy constructor
    67     IoError(const IoError &error) throw() : Exception() {
    68       message(error._message);
    69       file(error._file);
    70     }
    71 
    72     /// Constructor
    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() {
    85       IoError::message(message);
    86       IoError::file(file);
    87     }
    88 
    89     /// Constructor
    90     explicit IoError(const std::string &message,
    91                      const std::string &file) throw() {
    92       IoError::message(message);
    93       IoError::file(file);
    94     }
    95 
    96     /// Virtual destructor
    97     virtual ~IoError() throw() {}
    98 
    99     /// Set the error 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() {
    108       try {
    109         _message = message;
    110       } catch (...) {}
    111     }
    112 
    113     /// Set the file name
    114     void file(const std::string &file) throw() {
    115       try {
    116         _file = file;
    117       } catch (...) {}
    118     }
    119 
    120     /// Returns the error message
    121     const std::string& message() const throw() {
    122       return _message;
    123     }
    124 
    125     /// \brief Returns the filename
     238    ExceptionMember<std::string> _message;
     239    ExceptionMember<std::string> _file;
     240    int _line;
     241
     242    mutable ExceptionMember<std::string> _message_holder;
     243  public:
     244
     245    DataFormatError(const DataFormatError &dfe) :
     246      IoError(dfe), _message(dfe._message), _file(dfe._file),
     247      _line(dfe._line) {}
     248
     249    ///\e
     250    explicit DataFormatError(const char *the_message)
     251      : _message(the_message), _line(0) {}
     252
     253    ///\e
     254    DataFormatError(const std::string &file_name, int line_num,
     255                    const char *the_message)
     256      : _message(the_message), _line(line_num) { file(file_name); }
     257
     258    ///\e
     259    void line(int ln) { _line = ln; }
     260    ///\e
     261    void message(const std::string& msg) { _message.set(msg); }
     262    ///\e
     263    void file(const std::string &fl) { _file.set(fl); }
     264
     265    ///\e
     266    int line() const { return _line; }
     267    ///\e
     268    const char* message() const {
     269      if (_message.valid() && !_message.get().empty()) {
     270        return _message.get().c_str();
     271      } else {
     272        return 0;
     273      }
     274    }
     275
     276    /// \brief Returns the filename.
    126277    ///
    127     /// Returns the filename or an empty string if it was not specified.
    128     const std::string& file() const throw() {
    129       return _file;
    130     }
    131 
    132     /// \brief Returns a short error message
     278    /// Returns \e null if the filename was not specified.
     279    const char* file() const {
     280      if (_file.valid() && !_file.get().empty()) {
     281        return _file.get().c_str();
     282      } else {
     283        return 0;
     284      }
     285    }
     286
     287    ///\e
     288    virtual const char* what() const throw() {
     289      try {
     290        std::ostringstream ostr;
     291        ostr << "lemon:DataFormatError" << ": ";
     292        if (message()) ostr << message();
     293        if( file() || line() != 0 ) {
     294          ostr << " (";
     295          if( file() ) ostr << "in file '" << file() << "'";
     296          if( file() && line() != 0 ) ostr << " ";
     297          if( line() != 0 ) ostr << "at line " << line();
     298          ostr << ")";
     299        }
     300        _message_holder.set(ostr.str());
     301      }
     302      catch (...) {}
     303      if( _message_holder.valid()) return _message_holder.get().c_str();
     304      return "lemon:DataFormatError";
     305    }
     306
     307    virtual ~DataFormatError() throw() {}
     308  };
     309
     310  ///\e
     311  class FileOpenError : public IoError {
     312  protected:
     313    ExceptionMember<std::string> _file;
     314
     315    mutable ExceptionMember<std::string> _message_holder;
     316  public:
     317
     318    FileOpenError(const FileOpenError &foe) :
     319      IoError(foe), _file(foe._file) {}
     320
     321    ///\e
     322    explicit FileOpenError(const std::string& fl)
     323      : _file(fl) {}
     324
     325
     326    ///\e
     327    void file(const std::string &fl) { _file.set(fl); }
     328
     329    /// \brief Returns the filename.
    133330    ///
    134     /// Returns a short error message which contains the message and the
    135     /// file name.
    136     virtual const char* what() const throw() {
    137       try {
    138         _what.clear();
    139         std::ostringstream oss;
    140         oss << "lemon:IoError" << ": ";
    141         oss << _message;
    142         if (!_file.empty()) {
    143           oss << " ('" << _file << "')";
    144         }
    145         _what = oss.str();
     331    /// Returns \e null if the filename was not specified.
     332    const char* file() const {
     333      if (_file.valid() && !_file.get().empty()) {
     334        return _file.get().c_str();
     335      } else {
     336        return 0;
     337      }
     338    }
     339
     340    ///\e
     341    virtual const char* what() const throw() {
     342      try {
     343        std::ostringstream ostr;
     344        ostr << "lemon::FileOpenError" << ": ";
     345        ostr << "Cannot open file - " << file();
     346        _message_holder.set(ostr.str());
    146347      }
    147348      catch (...) {}
    148       if (!_what.empty()) return _what.c_str();
    149       else return "lemon:IoError";
    150     }
    151 
    152   };
    153 
    154   /// \brief Format error
    155   ///
    156   /// This exception is thrown when an input file has wrong
    157   /// format or a data representation is not legal.
    158   class FormatError : public Exception {
     349      if( _message_holder.valid()) return _message_holder.get().c_str();
     350      return "lemon::FileOpenError";
     351    }
     352    virtual ~FileOpenError() throw() {}
     353  };
     354
     355  class IoParameterError : public IoError {
    159356  protected:
    160     std::string _message;
    161     std::string _file;
    162     int _line;
    163 
    164     mutable std::string _what;
    165   public:
    166 
    167     /// Copy constructor
    168     FormatError(const FormatError &error) throw() : Exception() {
    169       message(error._message);
    170       file(error._file);
    171       line(error._line);
    172     }
    173 
    174     /// Constructor
    175     explicit FormatError(const char *message) throw() {
    176       FormatError::message(message);
    177       _line = 0;
    178     }
    179 
    180     /// Constructor
    181     explicit FormatError(const std::string &message) throw() {
    182       FormatError::message(message);
    183       _line = 0;
    184     }
    185 
    186     /// Constructor
    187     explicit FormatError(const char *message,
    188                          const std::string &file, int line = 0) throw() {
    189       FormatError::message(message);
    190       FormatError::file(file);
    191       FormatError::line(line);
    192     }
    193 
    194     /// Constructor
    195     explicit FormatError(const std::string &message,
    196                          const std::string &file, int line = 0) throw() {
    197       FormatError::message(message);
    198       FormatError::file(file);
    199       FormatError::line(line);
    200     }
    201 
    202     /// Virtual destructor
    203     virtual ~FormatError() throw() {}
    204 
    205     /// Set the line number
    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() {
    217       try {
    218         _message = message;
    219       } catch (...) {}
    220     }
    221 
    222     /// Set the file name
    223     void file(const std::string &file) throw() {
    224       try {
    225         _file = file;
    226       } catch (...) {}
    227     }
    228 
    229     /// \brief Returns the line number
     357    ExceptionMember<std::string> _message;
     358    ExceptionMember<std::string> _file;
     359
     360    mutable ExceptionMember<std::string> _message_holder;
     361  public:
     362
     363    IoParameterError(const IoParameterError &ile) :
     364      IoError(ile), _message(ile._message), _file(ile._file) {}
     365
     366    ///\e
     367    explicit IoParameterError(const char *the_message)
     368      : _message(the_message) {}
     369
     370    ///\e
     371    IoParameterError(const char *file_name, const char *the_message)
     372      : _message(the_message), _file(file_name) {}
     373
     374     ///\e
     375    void message(const std::string& msg) { _message.set(msg); }
     376    ///\e
     377    void file(const std::string &fl) { _file.set(fl); }
     378
     379     ///\e
     380    const char* message() const {
     381      if (_message.valid()) {
     382        return _message.get().c_str();
     383      } else {
     384        return 0;
     385      }
     386    }
     387
     388    /// \brief Returns the filename.
    230389    ///
    231     /// Returns the line number or zero if it was not specified.
    232     int line() const throw() { return _line; }
    233 
    234     /// Returns the error message
    235     const std::string& message() const throw() {
    236       return _message;
    237     }
    238 
    239     /// \brief Returns the filename
    240     ///
    241     /// Returns the filename or an empty string if it was not specified.
    242     const std::string& file() const throw() {
    243       return _file;
    244     }
    245 
    246     /// \brief Returns a short error message
    247     ///
    248     /// Returns a short error message which contains the message, the
    249     /// file name and the line number.
    250     virtual const char* what() const throw() {
    251       try {
    252         _what.clear();
    253         std::ostringstream oss;
    254         oss << "lemon:FormatError" << ": ";
    255         oss << _message;
    256         if (!_file.empty() || _line != 0) {
    257           oss << " (";
    258           if (!_file.empty()) oss << "in file '" << _file << "'";
    259           if (!_file.empty() && _line != 0) oss << " ";
    260           if (_line != 0) oss << "at line " << _line;
    261           oss << ")";
    262         }
    263         _what = oss.str();
     390    /// Returns \c 0 if the filename was not specified.
     391    const char* file() const {
     392      if (_file.valid()) {
     393        return _file.get().c_str();
     394      } else {
     395        return 0;
     396      }
     397    }
     398
     399    ///\e
     400    virtual const char* what() const throw() {
     401      try {
     402        std::ostringstream ostr;
     403        if (message()) ostr << message();
     404        if (file()) ostr << "(when reading file '" << file() << "')";
     405        _message_holder.set(ostr.str());
    264406      }
    265407      catch (...) {}
    266       if (!_what.empty()) return _what.c_str();
    267       else return "lemon:FormatError";
    268     }
    269 
     408      if( _message_holder.valid() ) return _message_holder.get().c_str();
     409      return "lemon:IoParameterError";
     410    }
     411    virtual ~IoParameterError() throw() {}
    270412  };
    271413
  • lemon/graph_to_eps.h

    r291 r280  
    4141#include<lemon/color.h>
    4242#include<lemon/bits/bezier.h>
    43 #include<lemon/error.h>
    4443
    4544
     
    11681167graphToEps(G &g,const char *file_name)
    11691168{
    1170   std::ostream* os = new std::ofstream(file_name);
    1171   if (!(*os)) {
    1172     delete os;
    1173     throw IoError("Cannot write file", file_name);
    1174   }
    11751169  return GraphToEps<DefaultGraphToEpsTraits<G> >
    1176     (DefaultGraphToEpsTraits<G>(g,*os,true));
     1170    (DefaultGraphToEpsTraits<G>(g,*new std::ofstream(file_name),true));
    11771171}
    11781172
     
    11891183graphToEps(G &g,const std::string& file_name)
    11901184{
    1191   std::ostream* os = new std::ofstream(file_name.c_str());
    1192   if (!(*os)) {
    1193     delete os;
    1194     throw IoError("Cannot write file", file_name);
    1195   }
    11961185  return GraphToEps<DefaultGraphToEpsTraits<G> >
    1197     (DefaultGraphToEpsTraits<G>(g,*os,true));
     1186    (DefaultGraphToEpsTraits<G>(g,*new std::ofstream(file_name.c_str()),true));
    11981187}
    11991188
  • lemon/lgf_reader.h

    r291 r236  
    4949        std::istringstream is(str);
    5050        Value value;
    51         if (!(is >> value)) {
    52           throw FormatError("Cannot read token");
    53         }
     51        is >> value;
    5452
    5553        char c;
    5654        if (is >> std::ws >> c) {
    57           throw FormatError("Remaining characters in token");
     55          throw DataFormatError("Remaining characters in token");
    5856        }
    5957        return value;
     
    169167          std::ostringstream msg;
    170168          msg << "Item not found: " << str;
    171           throw FormatError(msg.str());
     169          throw DataFormatError(msg.str().c_str());
    172170        }
    173171        return it->second;
     
    187185      typename Graph::Arc operator()(const std::string& str) {
    188186        if (str.empty() || (str[0] != '+' && str[0] != '-')) {
    189           throw FormatError("Item must start with '+' or '-'");
     187          throw DataFormatError("Item must start with '+' or '-'");
    190188        }
    191189        typename std::map<std::string, typename Graph::Edge>
    192190          ::const_iterator it = _map.find(str.substr(1));
    193191        if (it == _map.end()) {
    194           throw FormatError("Item not found");
     192          throw DataFormatError("Item not found");
    195193        }
    196194        return _graph.direct(it->second, str[0] == '+');
     
    238236      char c;
    239237      if (!is.get(c))
    240         throw FormatError("Escape format error");
     238        throw DataFormatError("Escape format error");
    241239
    242240      switch (c) {
     
    267265          int code;
    268266          if (!is.get(c) || !isHex(c))
    269             throw FormatError("Escape format error");
     267            throw DataFormatError("Escape format error");
    270268          else if (code = valueHex(c), !is.get(c) || !isHex(c)) is.putback(c);
    271269          else code = code * 16 + valueHex(c);
     
    276274          int code;
    277275          if (!isOct(c))
    278             throw FormatError("Escape format error");
     276            throw DataFormatError("Escape format error");
    279277          else if (code = valueOct(c), !is.get(c) || !isOct(c))
    280278            is.putback(c);
     
    303301        }
    304302        if (!is)
    305           throw FormatError("Quoted format error");
     303          throw DataFormatError("Quoted format error");
    306304      } else {
    307305        is.putback(c);
     
    463461    std::istream* _is;
    464462    bool local_is;
    465     std::string _filename;
    466463
    467464    Digraph& _digraph;
     
    513510    /// file.
    514511    DigraphReader(const std::string& fn, Digraph& digraph)
    515       : _is(new std::ifstream(fn.c_str())), local_is(true),
    516         _filename(fn), _digraph(digraph),
     512      : _is(new std::ifstream(fn.c_str())), local_is(true), _digraph(digraph),
    517513        _use_nodes(false), _use_arcs(false),
    518         _skip_nodes(false), _skip_arcs(false) {
    519       if (!(*_is)) throw IoError("Cannot open file", fn);
    520     }
     514        _skip_nodes(false), _skip_arcs(false) {}
    521515
    522516    /// \brief Constructor
     
    525519    /// file.
    526520    DigraphReader(const char* fn, Digraph& digraph)
    527       : _is(new std::ifstream(fn)), local_is(true),
    528         _filename(fn), _digraph(digraph),
     521      : _is(new std::ifstream(fn)), local_is(true), _digraph(digraph),
    529522        _use_nodes(false), _use_arcs(false),
    530         _skip_nodes(false), _skip_arcs(false) {
    531       if (!(*_is)) throw IoError("Cannot open file", fn);
    532     }
     523        _skip_nodes(false), _skip_arcs(false) {}
    533524
    534525    /// \brief Destructor
     
    855846        if (readSuccess() && line) line.putback(c);
    856847        if (!_node_maps.empty())
    857           throw FormatError("Cannot find map names");
     848          throw DataFormatError("Cannot find map names");
    858849        return;
    859850      }
     
    869860            std::ostringstream msg;
    870861            msg << "Multiple occurence of node map: " << map;
    871             throw FormatError(msg.str());
     862            throw DataFormatError(msg.str().c_str());
    872863          }
    873864          maps.insert(std::make_pair(map, index));
     
    880871          if (jt == maps.end()) {
    881872            std::ostringstream msg;
    882             msg << "Map not found: " << _node_maps[i].first;
    883             throw FormatError(msg.str());
     873            msg << "Map not found in file: " << _node_maps[i].first;
     874            throw DataFormatError(msg.str().c_str());
    884875          }
    885876          map_index[i] = jt->second;
     
    905896            std::ostringstream msg;
    906897            msg << "Column not found (" << i + 1 << ")";
    907             throw FormatError(msg.str());
     898            throw DataFormatError(msg.str().c_str());
    908899          }
    909900        }
    910901        if (line >> std::ws >> c)
    911           throw FormatError("Extra character at the end of line");
     902          throw DataFormatError("Extra character on the end of line");
    912903
    913904        Node n;
     
    918909        } else {
    919910          if (label_index == -1)
    920             throw FormatError("Label map not found");
     911            throw DataFormatError("Label map not found in file");
    921912          typename std::map<std::string, Node>::iterator it =
    922913            _node_index.find(tokens[label_index]);
     
    924915            std::ostringstream msg;
    925916            msg << "Node with label not found: " << tokens[label_index];
    926             throw FormatError(msg.str());
     917            throw DataFormatError(msg.str().c_str());
    927918          }
    928919          n = it->second;
     
    948939        if (readSuccess() && line) line.putback(c);
    949940        if (!_arc_maps.empty())
    950           throw FormatError("Cannot find map names");
     941          throw DataFormatError("Cannot find map names");
    951942        return;
    952943      }
     
    962953            std::ostringstream msg;
    963954            msg << "Multiple occurence of arc map: " << map;
    964             throw FormatError(msg.str());
     955            throw DataFormatError(msg.str().c_str());
    965956          }
    966957          maps.insert(std::make_pair(map, index));
     
    973964          if (jt == maps.end()) {
    974965            std::ostringstream msg;
    975             msg << "Map not found: " << _arc_maps[i].first;
    976             throw FormatError(msg.str());
     966            msg << "Map not found in file: " << _arc_maps[i].first;
     967            throw DataFormatError(msg.str().c_str());
    977968          }
    978969          map_index[i] = jt->second;
     
    997988
    998989        if (!_reader_bits::readToken(line, source_token))
    999           throw FormatError("Source not found");
     990          throw DataFormatError("Source not found");
    1000991
    1001992        if (!_reader_bits::readToken(line, target_token))
    1002           throw FormatError("Target not found");
     993          throw DataFormatError("Target not found");
    1003994
    1004995        std::vector<std::string> tokens(map_num);
     
    1007998            std::ostringstream msg;
    1008999            msg << "Column not found (" << i + 1 << ")";
    1009             throw FormatError(msg.str());
     1000            throw DataFormatError(msg.str().c_str());
    10101001          }
    10111002        }
    10121003        if (line >> std::ws >> c)
    1013           throw FormatError("Extra character at the end of line");
     1004          throw DataFormatError("Extra character on the end of line");
    10141005
    10151006        Arc a;
     
    10221013            std::ostringstream msg;
    10231014            msg << "Item not found: " << source_token;
    1024             throw FormatError(msg.str());
     1015            throw DataFormatError(msg.str().c_str());
    10251016          }
    10261017          Node source = it->second;
     
    10301021            std::ostringstream msg;
    10311022            msg << "Item not found: " << target_token;
    1032             throw FormatError(msg.str());
     1023            throw DataFormatError(msg.str().c_str());
    10331024          }
    10341025          Node target = it->second;
     
    10391030        } else {
    10401031          if (label_index == -1)
    1041             throw FormatError("Label map not found");
     1032            throw DataFormatError("Label map not found in file");
    10421033          typename std::map<std::string, Arc>::iterator it =
    10431034            _arc_index.find(tokens[label_index]);
     
    10451036            std::ostringstream msg;
    10461037            msg << "Arc with label not found: " << tokens[label_index];
    1047             throw FormatError(msg.str());
     1038            throw DataFormatError(msg.str().c_str());
    10481039          }
    10491040          a = it->second;
     
    10701061        std::string attr, token;
    10711062        if (!_reader_bits::readToken(line, attr))
    1072           throw FormatError("Attribute name not found");
     1063          throw DataFormatError("Attribute name not found");
    10731064        if (!_reader_bits::readToken(line, token))
    1074           throw FormatError("Attribute value not found");
     1065          throw DataFormatError("Attribute value not found");
    10751066        if (line >> c)
    1076           throw FormatError("Extra character at the end of line");
     1067          throw DataFormatError("Extra character on the end of line");
    10771068
    10781069        {
     
    10801071          if (it != read_attr.end()) {
    10811072            std::ostringstream msg;
    1082             msg << "Multiple occurence of attribute: " << attr;
    1083             throw FormatError(msg.str());
     1073            msg << "Multiple occurence of attribute " << attr;
     1074            throw DataFormatError(msg.str().c_str());
    10841075          }
    10851076          read_attr.insert(attr);
     
    11021093        if (read_attr.find(it->first) == read_attr.end()) {
    11031094          std::ostringstream msg;
    1104           msg << "Attribute not found: " << it->first;
    1105           throw FormatError(msg.str());
     1095          msg << "Attribute not found in file: " << it->first;
     1096          throw DataFormatError(msg.str().c_str());
    11061097        }
    11071098      }
     
    11181109    void run() {
    11191110      LEMON_ASSERT(_is != 0, "This reader assigned to an other reader");
     1111      if (!*_is) {
     1112        throw DataFormatError("Cannot find file");
     1113      }
    11201114
    11211115      bool nodes_done = _skip_nodes;
     
    11361130
    11371131          if (line >> c)
    1138             throw FormatError("Extra character at the end of line");
     1132            throw DataFormatError("Extra character on the end of line");
    11391133
    11401134          if (section == "nodes" && !nodes_done) {
     
    11581152            skipSection();
    11591153          }
    1160         } catch (FormatError& error) {
     1154        } catch (DataFormatError& error) {
    11611155          error.line(line_num);
    1162           error.file(_filename);
    11631156          throw;
    11641157        }
     
    11661159
    11671160      if (!nodes_done) {
    1168         throw FormatError("Section @nodes not found");
     1161        throw DataFormatError("Section @nodes not found");
    11691162      }
    11701163
    11711164      if (!arcs_done) {
    1172         throw FormatError("Section @arcs not found");
     1165        throw DataFormatError("Section @arcs not found");
    11731166      }
    11741167
    11751168      if (!attributes_done && !_attributes.empty()) {
    1176         throw FormatError("Section @attributes not found");
     1169        throw DataFormatError("Section @attributes not found");
    11771170      }
    11781171
     
    12521245    std::istream* _is;
    12531246    bool local_is;
    1254     std::string _filename;
    12551247
    12561248    Graph& _graph;
     
    13021294    /// file.
    13031295    GraphReader(const std::string& fn, Graph& graph)
    1304       : _is(new std::ifstream(fn.c_str())), local_is(true),
    1305         _filename(fn), _graph(graph),
     1296      : _is(new std::ifstream(fn.c_str())), local_is(true), _graph(graph),
    13061297        _use_nodes(false), _use_edges(false),
    1307         _skip_nodes(false), _skip_edges(false) {
    1308       if (!(*_is)) throw IoError("Cannot open file", fn);
    1309     }
     1298        _skip_nodes(false), _skip_edges(false) {}
    13101299
    13111300    /// \brief Constructor
     
    13141303    /// file.
    13151304    GraphReader(const char* fn, Graph& graph)
    1316       : _is(new std::ifstream(fn)), local_is(true),
    1317         _filename(fn), _graph(graph),
     1305      : _is(new std::ifstream(fn)), local_is(true), _graph(graph),
    13181306        _use_nodes(false), _use_edges(false),
    1319         _skip_nodes(false), _skip_edges(false) {
    1320       if (!(*_is)) throw IoError("Cannot open file", fn);
    1321     }
     1307        _skip_nodes(false), _skip_edges(false) {}
    13221308
    13231309    /// \brief Destructor
     
    16881674        if (readSuccess() && line) line.putback(c);
    16891675        if (!_node_maps.empty())
    1690           throw FormatError("Cannot find map names");
     1676          throw DataFormatError("Cannot find map names");
    16911677        return;
    16921678      }
     
    17021688            std::ostringstream msg;
    17031689            msg << "Multiple occurence of node map: " << map;
    1704             throw FormatError(msg.str());
     1690            throw DataFormatError(msg.str().c_str());
    17051691          }
    17061692          maps.insert(std::make_pair(map, index));
     
    17131699          if (jt == maps.end()) {
    17141700            std::ostringstream msg;
    1715             msg << "Map not found: " << _node_maps[i].first;
    1716             throw FormatError(msg.str());
     1701            msg << "Map not found in file: " << _node_maps[i].first;
     1702            throw DataFormatError(msg.str().c_str());
    17171703          }
    17181704          map_index[i] = jt->second;
     
    17381724            std::ostringstream msg;
    17391725            msg << "Column not found (" << i + 1 << ")";
    1740             throw FormatError(msg.str());
     1726            throw DataFormatError(msg.str().c_str());
    17411727          }
    17421728        }
    17431729        if (line >> std::ws >> c)
    1744           throw FormatError("Extra character at the end of line");
     1730          throw DataFormatError("Extra character on the end of line");
    17451731
    17461732        Node n;
     
    17511737        } else {
    17521738          if (label_index == -1)
    1753             throw FormatError("Label map not found");
     1739            throw DataFormatError("Label map not found in file");
    17541740          typename std::map<std::string, Node>::iterator it =
    17551741            _node_index.find(tokens[label_index]);
     
    17571743            std::ostringstream msg;
    17581744            msg << "Node with label not found: " << tokens[label_index];
    1759             throw FormatError(msg.str());
     1745            throw DataFormatError(msg.str().c_str());
    17601746          }
    17611747          n = it->second;
     
    17811767        if (readSuccess() && line) line.putback(c);
    17821768        if (!_edge_maps.empty())
    1783           throw FormatError("Cannot find map names");
     1769          throw DataFormatError("Cannot find map names");
    17841770        return;
    17851771      }
     
    17951781            std::ostringstream msg;
    17961782            msg << "Multiple occurence of edge map: " << map;
    1797             throw FormatError(msg.str());
     1783            throw DataFormatError(msg.str().c_str());
    17981784          }
    17991785          maps.insert(std::make_pair(map, index));
     
    18061792          if (jt == maps.end()) {
    18071793            std::ostringstream msg;
    1808             msg << "Map not found: " << _edge_maps[i].first;
    1809             throw FormatError(msg.str());
     1794            msg << "Map not found in file: " << _edge_maps[i].first;
     1795            throw DataFormatError(msg.str().c_str());
    18101796          }
    18111797          map_index[i] = jt->second;
     
    18301816
    18311817        if (!_reader_bits::readToken(line, source_token))
    1832           throw FormatError("Node u not found");
     1818          throw DataFormatError("Node u not found");
    18331819
    18341820        if (!_reader_bits::readToken(line, target_token))
    1835           throw FormatError("Node v not found");
     1821          throw DataFormatError("Node v not found");
    18361822
    18371823        std::vector<std::string> tokens(map_num);
     
    18401826            std::ostringstream msg;
    18411827            msg << "Column not found (" << i + 1 << ")";
    1842             throw FormatError(msg.str());
     1828            throw DataFormatError(msg.str().c_str());
    18431829          }
    18441830        }
    18451831        if (line >> std::ws >> c)
    1846           throw FormatError("Extra character at the end of line");
     1832          throw DataFormatError("Extra character on the end of line");
    18471833
    18481834        Edge e;
     
    18551841            std::ostringstream msg;
    18561842            msg << "Item not found: " << source_token;
    1857             throw FormatError(msg.str());
     1843            throw DataFormatError(msg.str().c_str());
    18581844          }
    18591845          Node source = it->second;
     
    18631849            std::ostringstream msg;
    18641850            msg << "Item not found: " << target_token;
    1865             throw FormatError(msg.str());
     1851            throw DataFormatError(msg.str().c_str());
    18661852          }
    18671853          Node target = it->second;
     
    18721858        } else {
    18731859          if (label_index == -1)
    1874             throw FormatError("Label map not found");
     1860            throw DataFormatError("Label map not found in file");
    18751861          typename std::map<std::string, Edge>::iterator it =
    18761862            _edge_index.find(tokens[label_index]);
     
    18781864            std::ostringstream msg;
    18791865            msg << "Edge with label not found: " << tokens[label_index];
    1880             throw FormatError(msg.str());
     1866            throw DataFormatError(msg.str().c_str());
    18811867          }
    18821868          e = it->second;
     
    19031889        std::string attr, token;
    19041890        if (!_reader_bits::readToken(line, attr))
    1905           throw FormatError("Attribute name not found");
     1891          throw DataFormatError("Attribute name not found");
    19061892        if (!_reader_bits::readToken(line, token))
    1907           throw FormatError("Attribute value not found");
     1893          throw DataFormatError("Attribute value not found");
    19081894        if (line >> c)
    1909           throw FormatError("Extra character at the end of line");
     1895          throw DataFormatError("Extra character on the end of line");
    19101896
    19111897        {
     
    19131899          if (it != read_attr.end()) {
    19141900            std::ostringstream msg;
    1915             msg << "Multiple occurence of attribute: " << attr;
    1916             throw FormatError(msg.str());
     1901            msg << "Multiple occurence of attribute " << attr;
     1902            throw DataFormatError(msg.str().c_str());
    19171903          }
    19181904          read_attr.insert(attr);
     
    19351921        if (read_attr.find(it->first) == read_attr.end()) {
    19361922          std::ostringstream msg;
    1937           msg << "Attribute not found: " << it->first;
    1938           throw FormatError(msg.str());
     1923          msg << "Attribute not found in file: " << it->first;
     1924          throw DataFormatError(msg.str().c_str());
    19391925        }
    19401926      }
     
    19701956
    19711957          if (line >> c)
    1972             throw FormatError("Extra character at the end of line");
     1958            throw DataFormatError("Extra character on the end of line");
    19731959
    19741960          if (section == "nodes" && !nodes_done) {
     
    19921978            skipSection();
    19931979          }
    1994         } catch (FormatError& error) {
     1980        } catch (DataFormatError& error) {
    19951981          error.line(line_num);
    1996           error.file(_filename);
    19971982          throw;
    19981983        }
     
    20001985
    20011986      if (!nodes_done) {
    2002         throw FormatError("Section @nodes not found");
     1987        throw DataFormatError("Section @nodes not found");
    20031988      }
    20041989
    20051990      if (!edges_done) {
    2006         throw FormatError("Section @edges not found");
     1991        throw DataFormatError("Section @edges not found");
    20071992      }
    20081993
    20091994      if (!attributes_done && !_attributes.empty()) {
    2010         throw FormatError("Section @attributes not found");
     1995        throw DataFormatError("Section @attributes not found");
    20111996      }
    20121997
     
    20702055    std::istream* _is;
    20712056    bool local_is;
    2072     std::string _filename;
    20732057
    20742058    typedef std::map<std::string, _reader_bits::Section*> Sections;
     
    20912075    /// Construct a section reader, which reads from the given file.
    20922076    SectionReader(const std::string& fn)
    2093       : _is(new std::ifstream(fn.c_str())), local_is(true),
    2094         _filename(fn) {
    2095       if (!(*_is)) throw IoError("Cannot open file", fn);
    2096     }
     2077      : _is(new std::ifstream(fn.c_str())), local_is(true) {}
    20972078
    20982079    /// \brief Constructor
     
    21002081    /// Construct a section reader, which reads from the given file.
    21012082    SectionReader(const char* fn)
    2102       : _is(new std::ifstream(fn)), local_is(true),
    2103         _filename(fn) {
    2104       if (!(*_is)) throw IoError("Cannot open file", fn);
    2105     }
     2083      : _is(new std::ifstream(fn)), local_is(true) {}
    21062084
    21072085    /// \brief Destructor
     
    22592237
    22602238          if (line >> c)
    2261             throw FormatError("Extra character at the end of line");
     2239            throw DataFormatError("Extra character on the end of line");
    22622240
    22632241          if (extra_sections.find(section) != extra_sections.end()) {
    22642242            std::ostringstream msg;
    2265             msg << "Multiple occurence of section: " << section;
    2266             throw FormatError(msg.str());
     2243            msg << "Multiple occurence of section " << section;
     2244            throw DataFormatError(msg.str().c_str());
    22672245          }
    22682246          Sections::iterator it = _sections.find(section);
     
    22732251          readLine();
    22742252          skipSection();
    2275         } catch (FormatError& error) {
     2253        } catch (DataFormatError& error) {
    22762254          error.line(line_num);
    2277           error.file(_filename);
    22782255          throw;
    22792256        }
     
    22842261          std::ostringstream os;
    22852262          os << "Cannot find section: " << it->first;
    2286           throw FormatError(os.str());
     2263          throw DataFormatError(os.str().c_str());
    22872264        }
    22882265      }
     
    23842361    /// file.
    23852362    LgfContents(const std::string& fn)
    2386       : _is(new std::ifstream(fn.c_str())), local_is(true) {
    2387       if (!(*_is)) throw IoError("Cannot open file", fn);
    2388     }
     2363      : _is(new std::ifstream(fn.c_str())), local_is(true) {}
    23892364
    23902365    /// \brief Constructor
     
    23932368    /// file.
    23942369    LgfContents(const char* fn)
    2395       : _is(new std::ifstream(fn)), local_is(true) {
    2396       if (!(*_is)) throw IoError("Cannot open file", fn);
    2397     }
     2370      : _is(new std::ifstream(fn)), local_is(true) {}
    23982371
    23992372    /// \brief Destructor
  • lemon/lgf_writer.h

    r291 r248  
    5656    template <typename T>
    5757    bool operator<(const T&, const T&) {
    58       throw FormatError("Label map is not comparable");
     58      throw DataFormatError("Label map is not comparable");
    5959    }
    6060
     
    204204          _map.find(str);
    205205        if (it == _map.end()) {
    206           throw FormatError("Item not found");
     206          throw DataFormatError("Item not found");
    207207        }
    208208        return it->second;
     
    224224          ::const_iterator it = _map.find(val);
    225225        if (it == _map.end()) {
    226           throw FormatError("Item not found");
     226          throw DataFormatError("Item not found");
    227227        }
    228228        return (_graph.direction(val) ? '+' : '-') + it->second;
     
    463463    DigraphWriter(const std::string& fn, const Digraph& digraph)
    464464      : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph),
    465         _skip_nodes(false), _skip_arcs(false) {
    466       if (!(*_os)) throw IoError("Cannot write file", fn);
    467     }
     465        _skip_nodes(false), _skip_arcs(false) {}
    468466
    469467    /// \brief Constructor
     
    473471    DigraphWriter(const char* fn, const Digraph& digraph)
    474472      : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph),
    475         _skip_nodes(false), _skip_arcs(false) {
    476       if (!(*_os)) throw IoError("Cannot write file", fn);
    477     }
     473        _skip_nodes(false), _skip_arcs(false) {}
    478474
    479475    /// \brief Destructor
     
    10231019    GraphWriter(const std::string& fn, const Graph& graph)
    10241020      : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph),
    1025         _skip_nodes(false), _skip_edges(false) {
    1026       if (!(*_os)) throw IoError("Cannot write file", fn);
    1027     }
     1021        _skip_nodes(false), _skip_edges(false) {}
    10281022
    10291023    /// \brief Constructor
     
    10331027    GraphWriter(const char* fn, const Graph& graph)
    10341028      : _os(new std::ofstream(fn)), local_os(true), _graph(graph),
    1035         _skip_nodes(false), _skip_edges(false) {
    1036       if (!(*_os)) throw IoError("Cannot write file", fn);
    1037     }
     1029        _skip_nodes(false), _skip_edges(false) {}
    10381030
    10391031    /// \brief Destructor
     
    15851577    /// Construct a section writer, which writes into the given file.
    15861578    SectionWriter(const std::string& fn)
    1587       : _os(new std::ofstream(fn.c_str())), local_os(true) {
    1588       if (!(*_os)) throw IoError("Cannot write file", fn);
    1589     }
     1579      : _os(new std::ofstream(fn.c_str())), local_os(true) {}
    15901580
    15911581    /// \brief Constructor
     
    15931583    /// Construct a section writer, which writes into the given file.
    15941584    SectionWriter(const char* fn)
    1595       : _os(new std::ofstream(fn)), local_os(true) {
    1596       if (!(*_os)) throw IoError("Cannot write file", fn);
    1597     }
     1585      : _os(new std::ofstream(fn)), local_os(true) {}
    15981586
    15991587    /// \brief Destructor
Note: See TracChangeset for help on using the changeset viewer.