gravatar
deba@inf.elte.hu
deba@inf.elte.hu
Simplifying exceptions - Using asserts instead of exceptions for unitialized parameters - Only the IO exceptions are used in the lemon - DataFormatError is renamed to FormatError - The IoError is used for file access errors
0 11 0
default
11 files changed with 380 insertions and 511 deletions:
↑ Collapse diff ↑
Show white space 6 line context
... ...
@@ -51,3 +51,3 @@
51 51
      run();
52
  } catch (DataFormatError& error) { // check if there was any error
52
  } catch (Exception& error) { // check if there was any error
53 53
    std::cerr << "Error: " << error.what() << std::endl;
Ignore white space 6 line context
... ...
@@ -312,4 +312,5 @@
312 312
    ///It automatically converts to \c int, \c double, \c bool or
313
    ///\c std::string if the type of the option matches, otherwise it
314
    ///throws an exception (i.e. it performs runtime type checking).
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).
315 316
    class RefType
Ignore white space 6 line context
... ...
@@ -110,3 +110,3 @@
110 110
///
111
/// Macro for assertion with customizable message.  
111
/// Macro for assertion with customizable message.
112 112
/// \param exp An expression that must be convertible to \c bool.  If it is \c
Ignore white space 6 line context
... ...
@@ -137,12 +137,2 @@
137 137
  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
    };
148 138

	
... ...
@@ -234,3 +224,4 @@
234 224
      {
235
        throw UninitializedParameter();
225
        LEMON_ASSERT(false, "PredMap is not initialized");
226
        return 0; // ignore warnings
236 227
      }
... ...
@@ -252,3 +243,4 @@
252 243
      {
253
        throw UninitializedParameter();
244
        LEMON_ASSERT(false, "DistMap is not initialized");
245
        return 0; // ignore warnings
254 246
      }
... ...
@@ -270,3 +262,4 @@
270 262
      {
271
        throw UninitializedParameter();
263
        LEMON_ASSERT(false, "ReachedMap is not initialized");
264
        return 0; // ignore warnings
272 265
      }
... ...
@@ -288,3 +281,4 @@
288 281
      {
289
        throw UninitializedParameter();
282
        LEMON_ASSERT(false, "ProcessedMap is not initialized");
283
        return 0; // ignore warnings
290 284
      }
... ...
@@ -306,2 +300,3 @@
306 300
        return new ProcessedMap(g);
301
        return 0; // ignore warnings
307 302
      }
... ...
@@ -1042,3 +1037,2 @@
1042 1037
    {
1043
      if (s==INVALID || t==INVALID) throw UninitializedParameter();
1044 1038
      Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
... ...
@@ -1325,14 +1319,2 @@
1325 1319

	
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

	
1338 1320
    ///The traits class.
... ...
@@ -1391,3 +1373,4 @@
1391 1373
      static ReachedMap *createReachedMap(const Digraph &digraph) {
1392
        throw UninitializedParameter();
1374
        LEMON_ASSERT(false, "ReachedMap is not initialized");
1375
        return 0; // ignore warnings
1393 1376
      }
Ignore white space 6 line context
... ...
@@ -131,3 +131,2 @@
131 131
      ///
132
      /// It may throw an \ref UnderflowPriorityException.
133 132
      /// \param i The item.
Ignore white space 6 line context
... ...
@@ -138,12 +138,2 @@
138 138
  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
    };
149 139

	
... ...
@@ -234,3 +224,4 @@
234 224
      {
235
        throw UninitializedParameter();
225
        LEMON_ASSERT(false, "PredMap is not initialized");
226
        return 0; // ignore warnings
236 227
      }
... ...
@@ -252,3 +243,4 @@
252 243
      {
253
        throw UninitializedParameter();
244
        LEMON_ASSERT(false, "DistMap is not initialized");
245
        return 0; // ignore warnings
254 246
      }
... ...
@@ -270,3 +262,4 @@
270 262
      {
271
        throw UninitializedParameter();
263
        LEMON_ASSERT(false, "ReachedMap is not initialized");
264
        return 0; // ignore warnings
272 265
      }
... ...
@@ -288,3 +281,4 @@
288 281
      {
289
        throw UninitializedParameter();
282
        LEMON_ASSERT(false, "ProcessedMap is not initialized");
283
        return 0; // ignore warnings
290 284
      }
... ...
@@ -976,3 +970,2 @@
976 970
    {
977
      if (s==INVALID || t==INVALID) throw UninitializedParameter();
978 971
      Dfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
... ...
@@ -1272,14 +1265,2 @@
1272 1265

	
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

	
1285 1266
    ///The traits class.
... ...
@@ -1338,3 +1319,4 @@
1338 1319
      static ReachedMap *createReachedMap(const Digraph &digraph) {
1339
        throw UninitializedParameter();
1320
        LEMON_ASSERT(false, "ReachedMap is not initialized");
1321
        return 0; // ignore warnings
1340 1322
      }
Ignore white space 6 line context
... ...
@@ -227,12 +227,2 @@
227 227
  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
    };
238 228

	
... ...
@@ -334,3 +324,4 @@
334 324
      {
335
        throw UninitializedParameter();
325
        LEMON_ASSERT(false, "PredMap is not initialized");
326
        return 0; // ignore warnings
336 327
      }
... ...
@@ -353,3 +344,4 @@
353 344
      {
354
        throw UninitializedParameter();
345
        LEMON_ASSERT(false, "DistMap is not initialized");
346
        return 0; // ignore warnings
355 347
      }
... ...
@@ -372,3 +364,4 @@
372 364
      {
373
        throw UninitializedParameter();
365
        LEMON_ASSERT(false, "ProcessedMap is not initialized");
366
        return 0; // ignore warnings
374 367
      }
... ...
@@ -410,3 +403,4 @@
410 403
      static HeapCrossRef *createHeapCrossRef(const Digraph &) {
411
        throw UninitializedParameter();
404
        LEMON_ASSERT(false, "HeapCrossRef is not initialized");
405
        return 0; // ignore warnings
412 406
      }
... ...
@@ -414,3 +408,4 @@
414 408
      {
415
        throw UninitializedParameter();
409
        LEMON_ASSERT(false, "Heap is not initialized");
410
        return 0; // ignore warnings
416 411
      }
... ...
@@ -1160,3 +1155,2 @@
1160 1155
    {
1161
      if (s==INVALID) throw UninitializedParameter();
1162 1156
      Dijkstra<Digraph,LengthMap,TR>
... ...
@@ -1182,3 +1176,2 @@
1182 1176
    {
1183
      if (s==INVALID || t==INVALID) throw UninitializedParameter();
1184 1177
      Dijkstra<Digraph,LengthMap,TR>
Ignore white space 6 line context
... ...
@@ -37,131 +37,4 @@
37 37

	
38
  /// \brief Exception safe wrapper class.
38
  /// \brief Generic exception class.
39 39
  ///
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

	
167 40
  /// Base class for exceptions used in LEMON.
... ...
@@ -170,7 +43,7 @@
170 43
  public:
171
    ///\e
44
    ///\e Constructor
172 45
    Exception() {}
173
    ///\e
46
    ///\e Virtual destructor
174 47
    virtual ~Exception() throw() {}
175
    ///\e
48
    ///\e A short description of the exception
176 49
    virtual const char* what() const throw() {
... ...
@@ -180,233 +53,218 @@
180 53

	
181
  /// One of the two main subclasses of \ref Exception.
54
  /// \brief Input-Output error
55
  ///
56
  /// This exception is thrown when a file operation cannot be
57
  /// succeeded.
58
  class IoError : public Exception {
59
  protected:
60
    std::string _message;
61
    std::string _file;
182 62

	
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).
186
  ///
187
  /// A typical example for this is \ref UninitializedParameter.
188
  class LogicError : public Exception {
63
    mutable std::string _what;
189 64
  public:
65

	
66
    /// Copy constructor
67
    IoError(const IoError &error) {
68
      message(error._message);
69
      file(error._file);
70
    }
71

	
72
    /// 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) {
84
      IoError::message(message);
85
      IoError::file(file);
86
    }
87

	
88
    /// Constructor
89
    IoError(const std::string &file, const std::string &message) {
90
      IoError::message(message);
91
      IoError::file(file);
92
    }
93

	
94
    /// Virtual destructor
95
    virtual ~IoError() throw() {}
96

	
97
    /// 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) {
106
      try {
107
        _message = message;
108
      } catch (...) {}
109
    }
110

	
111
    /// Set the file name
112
    void file(const std::string &file) {
113
      try {
114
        _file = file;
115
      } catch (...) {}
116
    }
117

	
118
    /// Returns the error message
119
    const std::string& message() const {
120
      return _message;
121
    }
122

	
123
    /// \brief Returns the filename
124
    ///
125
    /// Returns the filename or empty string if the filename was not
126
    /// specified.
127
    const std::string& file() const {
128
      return _file;
129
    }
130

	
131
    /// \brief Returns a short error message
132
    ///
133
    /// Returns a short error message which contains the message, the
134
    /// file name and the line number.
190 135
    virtual const char* what() const throw() {
191
      return "lemon::LogicError";
136
      try {
137
        _what.clear();
138
        std::ostringstream oss;
139
        oss << "lemon:IoError" << ": ";
140
        oss << message();
141
        if (!file().empty()) {
142
          oss << " (";
143
          if (!file().empty()) oss << "with file '" << file() << "'";
144
          oss << ")";
145
        }
146
        _what = oss.str();
147
      }
148
      catch (...) {}
149
      if (!_what.empty()) return _what.c_str();
150
      else return "lemon:IoError";
192 151
    }
152

	
193 153
  };
194 154

	
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 {
155
  /// \brief Format error
156
  ///
157
  /// This class is used to indicate if an input file has wrong
158
  /// formatting, or a data representation is not legal.
159
  class FormatError : public Exception {
237 160
  protected:
238
    ExceptionMember<std::string> _message;
239
    ExceptionMember<std::string> _file;
161
    std::string _message;
162
    std::string _file;
240 163
    int _line;
241 164

	
242
    mutable ExceptionMember<std::string> _message_holder;
165
    mutable std::string _what;
243 166
  public:
244 167

	
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
      }
168
    /// Copy constructor
169
    FormatError(const FormatError &error) {
170
      message(error._message);
171
      file(error._file);
172
      line(error._line);
274 173
    }
275 174

	
276
    /// \brief Returns the filename.
277
    ///
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
      }
175
    /// Constructor
176
    explicit FormatError(const char *message) {
177
      FormatError::message(message);
178
      _line = 0;
285 179
    }
286 180

	
287
    ///\e
181
    /// Constructor
182
    explicit FormatError(const std::string &message) {
183
      FormatError::message(message);
184
      _line = 0;
185
    }
186

	
187
    /// Constructor
188
    FormatError(const std::string &file, int line, const char *message) {
189
      FormatError::message(message);
190
      FormatError::file(file);
191
      FormatError::line(line);
192
    }
193

	
194
    /// Constructor
195
    FormatError(const std::string &file, int line, const std::string &message) {
196
      FormatError::message(message);
197
      FormatError::file(file);
198
      FormatError::line(line);
199
    }
200

	
201
    /// Virtual destructor
202
    virtual ~FormatError() throw() {}
203

	
204
    /// 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) {
216
      try {
217
        _message = message;
218
      } catch (...) {}
219
    }
220

	
221
    /// Set the file name
222
    void file(const std::string &file) {
223
      try {
224
        _file = file;
225
      } catch (...) {}
226
    }
227

	
228
    /// \brief Returns the line number
229
    ///
230
    /// Returns the line number or zero if it was not specified.
231
    int line() const { return _line; }
232

	
233
    /// Returns the error message
234
    const std::string& message() const {
235
      return _message;
236
    }
237

	
238
    /// \brief Returns the filename
239
    ///
240
    /// Returns the filename or empty string if the filename was not
241
    /// specified.
242
    const std::string& file() const {
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.
288 250
    virtual const char* what() const throw() {
289 251
      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 << ")";
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 << ")";
299 262
        }
300
        _message_holder.set(ostr.str());
263
        _what = oss.str();
301 264
      }
302 265
      catch (...) {}
303
      if( _message_holder.valid()) return _message_holder.get().c_str();
304
      return "lemon:DataFormatError";
266
      if (!_what.empty()) return _what.c_str();
267
      else return "lemon:FormatError";
305 268
    }
306 269

	
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.
330
    ///
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());
347
      }
348
      catch (...) {}
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 {
356
  protected:
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.
389
    ///
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());
406
      }
407
      catch (...) {}
408
      if( _message_holder.valid() ) return _message_holder.get().c_str();
409
      return "lemon:IoParameterError";
410
    }
411
    virtual ~IoParameterError() throw() {}
412 270
  };
Ignore white space 6 line context
... ...
@@ -42,2 +42,3 @@
42 42
#include<lemon/bits/bezier.h>
43
#include<lemon/error.h>
43 44

	
... ...
@@ -1168,4 +1169,9 @@
1168 1169
{
1170
  std::ostream* os = new std::ofstream(file_name);
1171
  if (!(*os)) {
1172
    delete os;
1173
    throw IoError(file_name, "Cannot write file");
1174
  }
1169 1175
  return GraphToEps<DefaultGraphToEpsTraits<G> >
1170
    (DefaultGraphToEpsTraits<G>(g,*new std::ofstream(file_name),true));
1176
    (DefaultGraphToEpsTraits<G>(g,*os,true));
1171 1177
}
... ...
@@ -1184,4 +1190,9 @@
1184 1190
{
1191
  std::ostream* os = new std::ofstream(file_name.c_str());
1192
  if (!(*os)) {
1193
    delete os;
1194
    throw IoError(file_name, "Cannot write file");
1195
  }
1185 1196
  return GraphToEps<DefaultGraphToEpsTraits<G> >
1186
    (DefaultGraphToEpsTraits<G>(g,*new std::ofstream(file_name.c_str()),true));
1197
    (DefaultGraphToEpsTraits<G>(g,*os,true));
1187 1198
}
Ignore white space 6 line context
... ...
@@ -50,3 +50,5 @@
50 50
        Value value;
51
        is >> value;
51
        if (!(is >> value)) {
52
          throw FormatError("Cannot read token");
53
        }
52 54

	
... ...
@@ -54,3 +56,3 @@
54 56
        if (is >> std::ws >> c) {
55
          throw DataFormatError("Remaining characters in token");
57
          throw FormatError("Remaining characters in token");
56 58
        }
... ...
@@ -168,3 +170,3 @@
168 170
          msg << "Item not found: " << str;
169
          throw DataFormatError(msg.str().c_str());
171
          throw FormatError(msg.str());
170 172
        }
... ...
@@ -186,3 +188,3 @@
186 188
        if (str.empty() || (str[0] != '+' && str[0] != '-')) {
187
          throw DataFormatError("Item must start with '+' or '-'");
189
          throw FormatError("Item must start with '+' or '-'");
188 190
        }
... ...
@@ -191,3 +193,3 @@
191 193
        if (it == _map.end()) {
192
          throw DataFormatError("Item not found");
194
          throw FormatError("Item not found");
193 195
        }
... ...
@@ -237,3 +239,3 @@
237 239
      if (!is.get(c))
238
        throw DataFormatError("Escape format error");
240
        throw FormatError("Escape format error");
239 241

	
... ...
@@ -266,3 +268,3 @@
266 268
          if (!is.get(c) || !isHex(c))
267
            throw DataFormatError("Escape format error");
269
            throw FormatError("Escape format error");
268 270
          else if (code = valueHex(c), !is.get(c) || !isHex(c)) is.putback(c);
... ...
@@ -275,3 +277,3 @@
275 277
          if (!isOct(c))
276
            throw DataFormatError("Escape format error");
278
            throw FormatError("Escape format error");
277 279
          else if (code = valueOct(c), !is.get(c) || !isOct(c))
... ...
@@ -302,3 +304,3 @@
302 304
        if (!is)
303
          throw DataFormatError("Quoted format error");
305
          throw FormatError("Quoted format error");
304 306
      } else {
... ...
@@ -462,2 +464,3 @@
462 464
    bool local_is;
465
    std::string _filename;
463 466

	
... ...
@@ -511,5 +514,8 @@
511 514
    DigraphReader(const std::string& fn, Digraph& digraph)
512
      : _is(new std::ifstream(fn.c_str())), local_is(true), _digraph(digraph),
515
      : _is(new std::ifstream(fn.c_str())), local_is(true),
516
        _filename(fn), _digraph(digraph),
513 517
        _use_nodes(false), _use_arcs(false),
514
        _skip_nodes(false), _skip_arcs(false) {}
518
        _skip_nodes(false), _skip_arcs(false) {
519
      if (!(*_is)) throw IoError(fn, "Cannot open file");
520
    }
515 521

	
... ...
@@ -520,5 +526,8 @@
520 526
    DigraphReader(const char* fn, Digraph& digraph)
521
      : _is(new std::ifstream(fn)), local_is(true), _digraph(digraph),
527
      : _is(new std::ifstream(fn)), local_is(true),
528
        _filename(fn), _digraph(digraph),
522 529
        _use_nodes(false), _use_arcs(false),
523
        _skip_nodes(false), _skip_arcs(false) {}
530
        _skip_nodes(false), _skip_arcs(false) {
531
      if (!(*_is)) throw IoError(fn, "Cannot open file");
532
    }
524 533

	
... ...
@@ -847,3 +856,3 @@
847 856
        if (!_node_maps.empty())
848
          throw DataFormatError("Cannot find map names");
857
          throw FormatError("Cannot find map names");
849 858
        return;
... ...
@@ -861,3 +870,3 @@
861 870
            msg << "Multiple occurence of node map: " << map;
862
            throw DataFormatError(msg.str().c_str());
871
            throw FormatError(msg.str());
863 872
          }
... ...
@@ -873,3 +882,3 @@
873 882
            msg << "Map not found in file: " << _node_maps[i].first;
874
            throw DataFormatError(msg.str().c_str());
883
            throw FormatError(msg.str());
875 884
          }
... ...
@@ -897,3 +906,3 @@
897 906
            msg << "Column not found (" << i + 1 << ")";
898
            throw DataFormatError(msg.str().c_str());
907
            throw FormatError(msg.str());
899 908
          }
... ...
@@ -901,3 +910,3 @@
901 910
        if (line >> std::ws >> c)
902
          throw DataFormatError("Extra character on the end of line");
911
          throw FormatError("Extra character on the end of line");
903 912

	
... ...
@@ -910,3 +919,3 @@
910 919
          if (label_index == -1)
911
            throw DataFormatError("Label map not found in file");
920
            throw FormatError("Label map not found in file");
912 921
          typename std::map<std::string, Node>::iterator it =
... ...
@@ -916,3 +925,3 @@
916 925
            msg << "Node with label not found: " << tokens[label_index];
917
            throw DataFormatError(msg.str().c_str());
926
            throw FormatError(msg.str());
918 927
          }
... ...
@@ -940,3 +949,3 @@
940 949
        if (!_arc_maps.empty())
941
          throw DataFormatError("Cannot find map names");
950
          throw FormatError("Cannot find map names");
942 951
        return;
... ...
@@ -954,3 +963,3 @@
954 963
            msg << "Multiple occurence of arc map: " << map;
955
            throw DataFormatError(msg.str().c_str());
964
            throw FormatError(msg.str());
956 965
          }
... ...
@@ -966,3 +975,3 @@
966 975
            msg << "Map not found in file: " << _arc_maps[i].first;
967
            throw DataFormatError(msg.str().c_str());
976
            throw FormatError(msg.str());
968 977
          }
... ...
@@ -989,6 +998,6 @@
989 998
        if (!_reader_bits::readToken(line, source_token))
990
          throw DataFormatError("Source not found");
999
          throw FormatError("Source not found");
991 1000

	
992 1001
        if (!_reader_bits::readToken(line, target_token))
993
          throw DataFormatError("Target not found");
1002
          throw FormatError("Target not found");
994 1003

	
... ...
@@ -999,3 +1008,3 @@
999 1008
            msg << "Column not found (" << i + 1 << ")";
1000
            throw DataFormatError(msg.str().c_str());
1009
            throw FormatError(msg.str());
1001 1010
          }
... ...
@@ -1003,3 +1012,3 @@
1003 1012
        if (line >> std::ws >> c)
1004
          throw DataFormatError("Extra character on the end of line");
1013
          throw FormatError("Extra character on the end of line");
1005 1014

	
... ...
@@ -1014,3 +1023,3 @@
1014 1023
            msg << "Item not found: " << source_token;
1015
            throw DataFormatError(msg.str().c_str());
1024
            throw FormatError(msg.str());
1016 1025
          }
... ...
@@ -1022,3 +1031,3 @@
1022 1031
            msg << "Item not found: " << target_token;
1023
            throw DataFormatError(msg.str().c_str());
1032
            throw FormatError(msg.str());
1024 1033
          }
... ...
@@ -1031,3 +1040,3 @@
1031 1040
          if (label_index == -1)
1032
            throw DataFormatError("Label map not found in file");
1041
            throw FormatError("Label map not found in file");
1033 1042
          typename std::map<std::string, Arc>::iterator it =
... ...
@@ -1037,3 +1046,3 @@
1037 1046
            msg << "Arc with label not found: " << tokens[label_index];
1038
            throw DataFormatError(msg.str().c_str());
1047
            throw FormatError(msg.str());
1039 1048
          }
... ...
@@ -1062,7 +1071,7 @@
1062 1071
        if (!_reader_bits::readToken(line, attr))
1063
          throw DataFormatError("Attribute name not found");
1072
          throw FormatError("Attribute name not found");
1064 1073
        if (!_reader_bits::readToken(line, token))
1065
          throw DataFormatError("Attribute value not found");
1074
          throw FormatError("Attribute value not found");
1066 1075
        if (line >> c)
1067
          throw DataFormatError("Extra character on the end of line");
1076
          throw FormatError("Extra character on the end of line");
1068 1077

	
... ...
@@ -1073,3 +1082,3 @@
1073 1082
            msg << "Multiple occurence of attribute " << attr;
1074
            throw DataFormatError(msg.str().c_str());
1083
            throw FormatError(msg.str());
1075 1084
          }
... ...
@@ -1095,3 +1104,3 @@
1095 1104
          msg << "Attribute not found in file: " << it->first;
1096
          throw DataFormatError(msg.str().c_str());
1105
          throw FormatError(msg.str());
1097 1106
        }
... ...
@@ -1111,3 +1120,3 @@
1111 1120
      if (!*_is) {
1112
        throw DataFormatError("Cannot find file");
1121
        throw FormatError("Cannot find file");
1113 1122
      }
... ...
@@ -1131,3 +1140,3 @@
1131 1140
          if (line >> c)
1132
            throw DataFormatError("Extra character on the end of line");
1141
            throw FormatError("Extra character on the end of line");
1133 1142

	
... ...
@@ -1153,4 +1162,5 @@
1153 1162
          }
1154
        } catch (DataFormatError& error) {
1163
        } catch (FormatError& error) {
1155 1164
          error.line(line_num);
1165
          error.file(_filename);
1156 1166
          throw;
... ...
@@ -1160,3 +1170,3 @@
1160 1170
      if (!nodes_done) {
1161
        throw DataFormatError("Section @nodes not found");
1171
        throw FormatError("Section @nodes not found");
1162 1172
      }
... ...
@@ -1164,3 +1174,3 @@
1164 1174
      if (!arcs_done) {
1165
        throw DataFormatError("Section @arcs not found");
1175
        throw FormatError("Section @arcs not found");
1166 1176
      }
... ...
@@ -1168,3 +1178,3 @@
1168 1178
      if (!attributes_done && !_attributes.empty()) {
1169
        throw DataFormatError("Section @attributes not found");
1179
        throw FormatError("Section @attributes not found");
1170 1180
      }
... ...
@@ -1246,2 +1256,3 @@
1246 1256
    bool local_is;
1257
    std::string _filename;
1247 1258

	
... ...
@@ -1295,5 +1306,8 @@
1295 1306
    GraphReader(const std::string& fn, Graph& graph)
1296
      : _is(new std::ifstream(fn.c_str())), local_is(true), _graph(graph),
1307
      : _is(new std::ifstream(fn.c_str())), local_is(true),
1308
        _filename(fn), _graph(graph),
1297 1309
        _use_nodes(false), _use_edges(false),
1298
        _skip_nodes(false), _skip_edges(false) {}
1310
        _skip_nodes(false), _skip_edges(false) {
1311
      if (!(*_is)) throw IoError(fn, "Cannot open file");
1312
    }
1299 1313

	
... ...
@@ -1304,5 +1318,8 @@
1304 1318
    GraphReader(const char* fn, Graph& graph)
1305
      : _is(new std::ifstream(fn)), local_is(true), _graph(graph),
1319
      : _is(new std::ifstream(fn)), local_is(true),
1320
        _filename(fn), _graph(graph),
1306 1321
        _use_nodes(false), _use_edges(false),
1307
        _skip_nodes(false), _skip_edges(false) {}
1322
        _skip_nodes(false), _skip_edges(false) {
1323
      if (!(*_is)) throw IoError(fn, "Cannot open file");
1324
    }
1308 1325

	
... ...
@@ -1675,3 +1692,3 @@
1675 1692
        if (!_node_maps.empty())
1676
          throw DataFormatError("Cannot find map names");
1693
          throw FormatError("Cannot find map names");
1677 1694
        return;
... ...
@@ -1689,3 +1706,3 @@
1689 1706
            msg << "Multiple occurence of node map: " << map;
1690
            throw DataFormatError(msg.str().c_str());
1707
            throw FormatError(msg.str());
1691 1708
          }
... ...
@@ -1701,3 +1718,3 @@
1701 1718
            msg << "Map not found in file: " << _node_maps[i].first;
1702
            throw DataFormatError(msg.str().c_str());
1719
            throw FormatError(msg.str());
1703 1720
          }
... ...
@@ -1725,3 +1742,3 @@
1725 1742
            msg << "Column not found (" << i + 1 << ")";
1726
            throw DataFormatError(msg.str().c_str());
1743
            throw FormatError(msg.str());
1727 1744
          }
... ...
@@ -1729,3 +1746,3 @@
1729 1746
        if (line >> std::ws >> c)
1730
          throw DataFormatError("Extra character on the end of line");
1747
          throw FormatError("Extra character on the end of line");
1731 1748

	
... ...
@@ -1738,3 +1755,3 @@
1738 1755
          if (label_index == -1)
1739
            throw DataFormatError("Label map not found in file");
1756
            throw FormatError("Label map not found in file");
1740 1757
          typename std::map<std::string, Node>::iterator it =
... ...
@@ -1744,3 +1761,3 @@
1744 1761
            msg << "Node with label not found: " << tokens[label_index];
1745
            throw DataFormatError(msg.str().c_str());
1762
            throw FormatError(msg.str());
1746 1763
          }
... ...
@@ -1768,3 +1785,3 @@
1768 1785
        if (!_edge_maps.empty())
1769
          throw DataFormatError("Cannot find map names");
1786
          throw FormatError("Cannot find map names");
1770 1787
        return;
... ...
@@ -1782,3 +1799,3 @@
1782 1799
            msg << "Multiple occurence of edge map: " << map;
1783
            throw DataFormatError(msg.str().c_str());
1800
            throw FormatError(msg.str());
1784 1801
          }
... ...
@@ -1794,3 +1811,3 @@
1794 1811
            msg << "Map not found in file: " << _edge_maps[i].first;
1795
            throw DataFormatError(msg.str().c_str());
1812
            throw FormatError(msg.str());
1796 1813
          }
... ...
@@ -1817,6 +1834,6 @@
1817 1834
        if (!_reader_bits::readToken(line, source_token))
1818
          throw DataFormatError("Node u not found");
1835
          throw FormatError("Node u not found");
1819 1836

	
1820 1837
        if (!_reader_bits::readToken(line, target_token))
1821
          throw DataFormatError("Node v not found");
1838
          throw FormatError("Node v not found");
1822 1839

	
... ...
@@ -1827,3 +1844,3 @@
1827 1844
            msg << "Column not found (" << i + 1 << ")";
1828
            throw DataFormatError(msg.str().c_str());
1845
            throw FormatError(msg.str());
1829 1846
          }
... ...
@@ -1831,3 +1848,3 @@
1831 1848
        if (line >> std::ws >> c)
1832
          throw DataFormatError("Extra character on the end of line");
1849
          throw FormatError("Extra character on the end of line");
1833 1850

	
... ...
@@ -1842,3 +1859,3 @@
1842 1859
            msg << "Item not found: " << source_token;
1843
            throw DataFormatError(msg.str().c_str());
1860
            throw FormatError(msg.str());
1844 1861
          }
... ...
@@ -1850,3 +1867,3 @@
1850 1867
            msg << "Item not found: " << target_token;
1851
            throw DataFormatError(msg.str().c_str());
1868
            throw FormatError(msg.str());
1852 1869
          }
... ...
@@ -1859,3 +1876,3 @@
1859 1876
          if (label_index == -1)
1860
            throw DataFormatError("Label map not found in file");
1877
            throw FormatError("Label map not found in file");
1861 1878
          typename std::map<std::string, Edge>::iterator it =
... ...
@@ -1865,3 +1882,3 @@
1865 1882
            msg << "Edge with label not found: " << tokens[label_index];
1866
            throw DataFormatError(msg.str().c_str());
1883
            throw FormatError(msg.str());
1867 1884
          }
... ...
@@ -1890,7 +1907,7 @@
1890 1907
        if (!_reader_bits::readToken(line, attr))
1891
          throw DataFormatError("Attribute name not found");
1908
          throw FormatError("Attribute name not found");
1892 1909
        if (!_reader_bits::readToken(line, token))
1893
          throw DataFormatError("Attribute value not found");
1910
          throw FormatError("Attribute value not found");
1894 1911
        if (line >> c)
1895
          throw DataFormatError("Extra character on the end of line");
1912
          throw FormatError("Extra character on the end of line");
1896 1913

	
... ...
@@ -1901,3 +1918,3 @@
1901 1918
            msg << "Multiple occurence of attribute " << attr;
1902
            throw DataFormatError(msg.str().c_str());
1919
            throw FormatError(msg.str());
1903 1920
          }
... ...
@@ -1923,3 +1940,3 @@
1923 1940
          msg << "Attribute not found in file: " << it->first;
1924
          throw DataFormatError(msg.str().c_str());
1941
          throw FormatError(msg.str());
1925 1942
        }
... ...
@@ -1957,3 +1974,3 @@
1957 1974
          if (line >> c)
1958
            throw DataFormatError("Extra character on the end of line");
1975
            throw FormatError("Extra character on the end of line");
1959 1976

	
... ...
@@ -1979,4 +1996,5 @@
1979 1996
          }
1980
        } catch (DataFormatError& error) {
1997
        } catch (FormatError& error) {
1981 1998
          error.line(line_num);
1999
          error.file(_filename);
1982 2000
          throw;
... ...
@@ -1986,3 +2004,3 @@
1986 2004
      if (!nodes_done) {
1987
        throw DataFormatError("Section @nodes not found");
2005
        throw FormatError("Section @nodes not found");
1988 2006
      }
... ...
@@ -1990,3 +2008,3 @@
1990 2008
      if (!edges_done) {
1991
        throw DataFormatError("Section @edges not found");
2009
        throw FormatError("Section @edges not found");
1992 2010
      }
... ...
@@ -1994,3 +2012,3 @@
1994 2012
      if (!attributes_done && !_attributes.empty()) {
1995
        throw DataFormatError("Section @attributes not found");
2013
        throw FormatError("Section @attributes not found");
1996 2014
      }
... ...
@@ -2056,2 +2074,3 @@
2056 2074
    bool local_is;
2075
    std::string _filename;
2057 2076

	
... ...
@@ -2076,3 +2095,6 @@
2076 2095
    SectionReader(const std::string& fn)
2077
      : _is(new std::ifstream(fn.c_str())), local_is(true) {}
2096
      : _is(new std::ifstream(fn.c_str())), local_is(true),
2097
        _filename(fn) {
2098
      if (!(*_is)) throw IoError(fn, "Cannot open file");
2099
    }
2078 2100

	
... ...
@@ -2082,3 +2104,6 @@
2082 2104
    SectionReader(const char* fn)
2083
      : _is(new std::ifstream(fn)), local_is(true) {}
2105
      : _is(new std::ifstream(fn)), local_is(true),
2106
        _filename(fn) {
2107
      if (!(*_is)) throw IoError(fn, "Cannot open file");
2108
    }
2084 2109

	
... ...
@@ -2238,3 +2263,3 @@
2238 2263
          if (line >> c)
2239
            throw DataFormatError("Extra character on the end of line");
2264
            throw FormatError("Extra character on the end of line");
2240 2265

	
... ...
@@ -2243,3 +2268,3 @@
2243 2268
            msg << "Multiple occurence of section " << section;
2244
            throw DataFormatError(msg.str().c_str());
2269
            throw FormatError(msg.str());
2245 2270
          }
... ...
@@ -2252,4 +2277,5 @@
2252 2277
          skipSection();
2253
        } catch (DataFormatError& error) {
2278
        } catch (FormatError& error) {
2254 2279
          error.line(line_num);
2280
          error.file(_filename);
2255 2281
          throw;
... ...
@@ -2262,3 +2288,3 @@
2262 2288
          os << "Cannot find section: " << it->first;
2263
          throw DataFormatError(os.str().c_str());
2289
          throw FormatError(os.str());
2264 2290
        }
... ...
@@ -2362,3 +2388,5 @@
2362 2388
    LgfContents(const std::string& fn)
2363
      : _is(new std::ifstream(fn.c_str())), local_is(true) {}
2389
      : _is(new std::ifstream(fn.c_str())), local_is(true) {
2390
      if (!(*_is)) throw IoError(fn, "Cannot open file");
2391
    }
2364 2392

	
... ...
@@ -2369,3 +2397,5 @@
2369 2397
    LgfContents(const char* fn)
2370
      : _is(new std::ifstream(fn)), local_is(true) {}
2398
      : _is(new std::ifstream(fn)), local_is(true) {
2399
      if (!(*_is)) throw IoError(fn, "Cannot open file");
2400
    }
2371 2401

	
Ignore white space 6 line context
... ...
@@ -57,3 +57,3 @@
57 57
    bool operator<(const T&, const T&) {
58
      throw DataFormatError("Label map is not comparable");
58
      throw FormatError("Label map is not comparable");
59 59
    }
... ...
@@ -205,3 +205,3 @@
205 205
        if (it == _map.end()) {
206
          throw DataFormatError("Item not found");
206
          throw FormatError("Item not found");
207 207
        }
... ...
@@ -225,3 +225,3 @@
225 225
        if (it == _map.end()) {
226
          throw DataFormatError("Item not found");
226
          throw FormatError("Item not found");
227 227
        }
... ...
@@ -464,3 +464,5 @@
464 464
      : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph),
465
        _skip_nodes(false), _skip_arcs(false) {}
465
        _skip_nodes(false), _skip_arcs(false) {
466
      if (!(*_os)) throw IoError(fn, "Cannot write file");
467
    }
466 468

	
... ...
@@ -472,3 +474,5 @@
472 474
      : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph),
473
        _skip_nodes(false), _skip_arcs(false) {}
475
        _skip_nodes(false), _skip_arcs(false) {
476
      if (!(*_os)) throw IoError(fn, "Cannot write file");
477
    }
474 478

	
... ...
@@ -1020,3 +1024,5 @@
1020 1024
      : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph),
1021
        _skip_nodes(false), _skip_edges(false) {}
1025
        _skip_nodes(false), _skip_edges(false) {
1026
      if (!(*_os)) throw IoError(fn, "Cannot write file");
1027
    }
1022 1028

	
... ...
@@ -1028,3 +1034,5 @@
1028 1034
      : _os(new std::ofstream(fn)), local_os(true), _graph(graph),
1029
        _skip_nodes(false), _skip_edges(false) {}
1035
        _skip_nodes(false), _skip_edges(false) {
1036
      if (!(*_os)) throw IoError(fn, "Cannot write file");
1037
    }
1030 1038

	
... ...
@@ -1578,3 +1586,5 @@
1578 1586
    SectionWriter(const std::string& fn)
1579
      : _os(new std::ofstream(fn.c_str())), local_os(true) {}
1587
      : _os(new std::ofstream(fn.c_str())), local_os(true) {
1588
      if (!(*_os)) throw IoError(fn, "Cannot write file");
1589
    }
1580 1590

	
... ...
@@ -1584,3 +1594,5 @@
1584 1594
    SectionWriter(const char* fn)
1585
      : _os(new std::ofstream(fn)), local_os(true) {}
1595
      : _os(new std::ofstream(fn)), local_os(true) {
1596
      if (!(*_os)) throw IoError(fn, "Cannot write file");
1597
    }
1586 1598

	
0 comments (0 inline)