lemon/error.h
changeset 2436 0c941c524b47
parent 2391 14a343be7a5a
child 2476 059dcdda37c5
equal deleted inserted replaced
13:9b83c84f84f0 14:8045065bfa0b
   473 
   473 
   474   /****************  Macros  ****************/
   474   /****************  Macros  ****************/
   475 
   475 
   476 
   476 
   477   template <typename Exception>
   477   template <typename Exception>
   478   inline void assert_fail(const char *file, int line, const char *func,
   478   inline void assert_fail(const char *file, int line, 
   479 		   Exception exception, const char *assertion = 0,
   479                           const char *func,
   480 		   bool do_abort=true)
   480                           Exception exception, 
       
   481                           const char *assertion = 0,
       
   482                           bool do_abort=true)
   481   {
   483   {
   482     using namespace std;
   484     using namespace std;
   483     cerr << file << ":" << line << ": ";
   485     cerr << file << ":" << line << ": ";
   484     if( func )
   486     if( func )
   485       cerr << func << ": ";
   487       cerr << func << ": ";
   508     cerr << endl;
   510     cerr << endl;
   509     if(do_abort)
   511     if(do_abort)
   510       abort();
   512       abort();
   511   }
   513   }
   512 
   514 
       
   515   template <>
       
   516   inline void assert_fail<std::string>(const char *file, int line, 
       
   517                                        const char *func,
       
   518                                        std::string message, 
       
   519                                        const char *assertion,
       
   520                                        bool do_abort)
       
   521   {
       
   522     assert_fail(file, line, func, message.c_str(), assertion, do_abort);
       
   523   }
       
   524 
   513   template <typename Exception>
   525   template <typename Exception>
   514   inline void assert_fail_failure(const char *file, int line, const char *func,
   526   inline void assert_fail_failure(const char *file, int line, const char *func,
   515 			   Exception exception, 
   527 			   Exception exception, 
   516 			   const char *assertion = 0,
   528 			   const char *assertion = 0,
   517 			   bool = true)
   529 			   bool = true)
   519     throw AssertionFailedError(file, line, func, exception.what(), assertion);
   531     throw AssertionFailedError(file, line, func, exception.what(), assertion);
   520   }
   532   }
   521 
   533 
   522   template <>
   534   template <>
   523   inline void assert_fail_failure<const char *>(const char *file, int line, 
   535   inline void assert_fail_failure<const char *>(const char *file, int line, 
   524 					 const char *func,
   536                                                 const char *func,
   525 					 const char *message, 
   537                                                 const char *message, 
   526 					 const char *assertion,
   538                                                 const char *assertion,
   527 					 bool)
   539                                                 bool)
   528   {
   540   {
   529     throw AssertionFailedError(file, line, func, message, assertion);
   541     throw AssertionFailedError(file, line, func, message, assertion);
       
   542   }
       
   543 
       
   544   template <>
       
   545   inline void assert_fail_failure<std::string>(const char *file, int line, 
       
   546                                                const char *func,
       
   547                                                std::string message, 
       
   548                                                const char *assertion,
       
   549                                                bool)
       
   550   {
       
   551     assert_fail_failure(file, line, func, message.c_str(), assertion, true);
   530   }
   552   }
   531 
   553 
   532   template <typename Exception> 
   554   template <typename Exception> 
   533   inline void assert_fail_exception(const char *file, int line, const char *func,
   555   inline void assert_fail_exception(const char *file, int line, const char *func,
   534 			     Exception exception, 
   556 			     Exception exception, 
   543 					   const char *message, 
   565 					   const char *message, 
   544 					   const char *assertion,
   566 					   const char *assertion,
   545 					   bool)
   567 					   bool)
   546   {
   568   {
   547     throw AssertionFailedError(file, line, func, message, assertion);
   569     throw AssertionFailedError(file, line, func, message, assertion);
       
   570   }
       
   571 
       
   572   template <>
       
   573   inline void assert_fail_exception<std::string>(const char *file, int line, 
       
   574                                                  const char *func,
       
   575                                                  std::string message, 
       
   576                                                  const char *assertion,
       
   577                                                  bool)
       
   578   {
       
   579     assert_fail_exception(file, line, func, message.c_str(), assertion, true);    
   548   }
   580   }
   549 
   581 
   550 /// @}
   582 /// @}
   551 
   583 
   552 }
   584 }