src/lemon/error.h
changeset 1241 dadc9987c537
parent 1209 dc9fdf77007f
child 1274 5676e48ca026
equal deleted inserted replaced
7:6a75c0bc79e6 8:3f428cc56104
   322     }
   322     }
   323 
   323 
   324     virtual ~DataFormatError() throw() {}
   324     virtual ~DataFormatError() throw() {}
   325   };
   325   };
   326 
   326 
   327   class IOLogicError : public IOError, public LogicError {
   327   class IOParameterError : public LogicError {
   328   protected:
   328   protected:
   329     ExceptionMember<std::string> _message;
   329     ExceptionMember<std::string> _message;
   330     ExceptionMember<std::string> _file;
   330     ExceptionMember<std::string> _file;
   331     int _line;
       
   332 
   331 
   333     mutable ExceptionMember<std::string> _message_holder;
   332     mutable ExceptionMember<std::string> _message_holder;
   334   public:
   333   public:
   335 
   334 
   336     IOLogicError(const IOLogicError &ile) : 
   335     IOParameterError(const IOParameterError &ile) : 
   337       IOError(ile), LogicError(ile), 
   336       LogicError(ile), _message(ile._message), _file(ile._file) {}
   338       _message(ile._message), _file(ile._file) {}
   337 
   339 
   338     ///\e 
   340     ///\e 
   339     explicit IOParameterError(const char *the_message)
   341     explicit IOLogicError(const char *the_message)
   340       : _message(the_message) {}
   342       : _message(the_message), _line(0) {}
   341 
   343 
   342     ///\e 
   344     ///\e 
   343     IOParameterError(const char *file_name, const char *the_message)
   345     IOLogicError(const char *file_name, const char *the_message)
       
   346       : _message(file_name), _file(file_name) {}
   344       : _message(file_name), _file(file_name) {}
   347 
   345 
   348      ///\e 
   346      ///\e 
   349     void message(const std::string& message) { _message.set(message); }
   347     void message(const std::string& message) { _message.set(message); }
   350     ///\e 
   348     ///\e 
   382       if( _message_holder.valid() ) return _message_holder.get().c_str();
   380       if( _message_holder.valid() ) return _message_holder.get().c_str();
   383       return exceptionName();
   381       return exceptionName();
   384     }
   382     }
   385 
   383 
   386     virtual const char* exceptionName() const {
   384     virtual const char* exceptionName() const {
   387       return "lemon::IOLogicError";
   385       return "lemon::IOParameterError";
   388     }
   386     }
   389 
   387 
   390     virtual ~IOLogicError() throw() {}
   388     virtual ~IOParameterError() throw() {}
   391   };
   389   };
   392 
   390 
   393 
   391 
   394   ///\e
   392   ///\e
   395   class AssertionFailedError : public LogicError {
   393   class AssertionFailedError : public LogicError {
   397     const char *assertion;
   395     const char *assertion;
   398     const char *file;
   396     const char *file;
   399     int line;
   397     int line;
   400     const char *function;
   398     const char *function;
   401     const char *message;
   399     const char *message;
       
   400 
       
   401     mutable ExceptionMember<std::string> _message_holder;
   402   public:
   402   public:
   403     ///\e
   403     ///\e
   404     AssertionFailedError(const char *_file, int _line, const char *func,
   404     AssertionFailedError(const char *_file, int _line, const char *func,
   405 			 const char *msg, const char *_assertion = 0) :
   405 			 const char *msg, const char *_assertion = 0) :
   406       assertion(_assertion), file(_file), line(_line), function(func),
   406       assertion(_assertion), file(_file), line(_line), function(func),
   424 	ostr << file << ":" << line << ": ";
   424 	ostr << file << ":" << line << ": ";
   425 	if( function )
   425 	if( function )
   426 	  ostr << function << ": ";
   426 	  ostr << function << ": ";
   427 	ostr << message;
   427 	ostr << message;
   428 	if( assertion )
   428 	if( assertion )
   429 	  ostr << " (assertion '" << assertion << "' failed)";
   429 	   ostr << " (assertion '" << assertion << "' failed)";
       
   430 	_message_holder.set(ostr.str());
   430 	return ostr.str().c_str();
   431 	return ostr.str().c_str();
   431       }
   432       }
   432       catch(...) {}
   433       catch(...) {}
       
   434       if( _message_holder.valid() ) return _message_holder.get().c_str();
   433       return exceptionName();
   435       return exceptionName();
   434     }
   436     }
   435 
   437 
   436     virtual const char* exceptionName() const {
   438     virtual const char* exceptionName() const {
   437       return "lemon::AssertionFailedError";
   439       return "lemon::AssertionFailedError";