Changeset 209:765619b7cbb2 in lemon-1.2 for lemon/error.h
- Timestamp:
- 07/13/08 20:51:02 (17 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/error.h
r108 r209 1 /* -*- C++-*-1 /* -*- mode: C++; indent-tabs-mode: nil; -*- 2 2 * 3 * This file is a part of LEMON, a generic C++ optimization library 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 5 * Copyright (C) 2003-2008 … … 46 46 ExceptionMember() throw() { 47 47 try { 48 48 ptr.reset(new Type()); 49 49 } catch (...) {} 50 50 } … … 52 52 ExceptionMember(const Type& type) throw() { 53 53 try { 54 55 56 54 ptr.reset(new Type()); 55 if (ptr.get() == 0) return; 56 *ptr = type; 57 57 } catch (...) {} 58 58 } … … 60 60 ExceptionMember(const ExceptionMember& copy) throw() { 61 61 try { 62 63 64 65 62 if (!copy.valid()) return; 63 ptr.reset(new Type()); 64 if (ptr.get() == 0) return; 65 *ptr = copy.get(); 66 66 } catch (...) {} 67 67 } … … 70 70 if (ptr.get() == 0) return; 71 71 try { 72 73 72 if (!copy.valid()) return; 73 *ptr = copy.get(); 74 74 } catch (...) {} 75 75 } … … 78 78 if (ptr.get() == 0) return; 79 79 try { 80 80 *ptr = type; 81 81 } catch (...) {} 82 82 } … … 110 110 bool init() throw() { 111 111 try { 112 112 buf.reset(new std::ostringstream); 113 113 } 114 114 catch(...) { 115 115 buf.reset(); 116 116 } 117 117 return buf.get(); … … 143 143 144 144 try { 145 145 *buf << t; 146 146 } 147 147 catch(...) { 148 148 buf.reset(); 149 149 } 150 150 return *this; … … 157 157 const char* mes = 0; 158 158 try { 159 159 mes = buf->str().c_str(); 160 160 } 161 161 catch(...) {} … … 255 255 ///\e 256 256 DataFormatError(const std::string &file_name, int line_num, 257 257 const char *the_message) 258 258 : _message(the_message), _line(line_num) { file(file_name); } 259 259 … … 270 270 const char* message() const { 271 271 if (_message.valid() && !_message.get().empty()) { 272 272 return _message.get().c_str(); 273 273 } else { 274 274 return 0; 275 275 } 276 276 } … … 281 281 const char* file() const { 282 282 if (_file.valid() && !_file.get().empty()) { 283 283 return _file.get().c_str(); 284 284 } else { 285 286 } 287 } 288 289 ///\e 290 virtual const char* what() const throw() { 291 try { 292 293 294 295 296 297 298 299 300 301 302 285 return 0; 286 } 287 } 288 289 ///\e 290 virtual const char* what() const throw() { 291 try { 292 std::ostringstream ostr; 293 ostr << "lemon:DataFormatError" << ": "; 294 if (message()) ostr << message(); 295 if( file() || line() != 0 ) { 296 ostr << " ("; 297 if( file() ) ostr << "in file '" << file() << "'"; 298 if( file() && line() != 0 ) ostr << " "; 299 if( line() != 0 ) ostr << "at line " << line(); 300 ostr << ")"; 301 } 302 _message_holder.set(ostr.str()); 303 303 } 304 304 catch (...) {} … … 334 334 const char* file() const { 335 335 if (_file.valid() && !_file.get().empty()) { 336 336 return _file.get().c_str(); 337 337 } else { 338 339 } 340 } 341 342 ///\e 343 virtual const char* what() const throw() { 344 try { 345 346 347 348 338 return 0; 339 } 340 } 341 342 ///\e 343 virtual const char* what() const throw() { 344 try { 345 std::ostringstream ostr; 346 ostr << "lemon::FileOpenError" << ": "; 347 ostr << "Cannot open file - " << file(); 348 _message_holder.set(ostr.str()); 349 349 } 350 350 catch (...) {} … … 382 382 const char* message() const { 383 383 if (_message.valid()) { 384 384 return _message.get().c_str(); 385 385 } else { 386 386 return 0; 387 387 } 388 388 } … … 393 393 const char* file() const { 394 394 if (_file.valid()) { 395 395 return _file.get().c_str(); 396 396 } else { 397 398 } 399 } 400 401 ///\e 402 virtual const char* what() const throw() { 403 try { 404 405 406 407 397 return 0; 398 } 399 } 400 401 ///\e 402 virtual const char* what() const throw() { 403 try { 404 std::ostringstream ostr; 405 if (message()) ostr << message(); 406 if (file()) ostr << "(when reading file '" << file() << "')"; 407 _message_holder.set(ostr.str()); 408 408 } 409 409 catch (...) {}
Note: See TracChangeset
for help on using the changeset viewer.