COIN-OR::LEMON - Graph Library

Changeset 1785:606178a14011 in lemon-0.x


Ignore:
Timestamp:
11/10/05 13:40:58 (14 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2323
Message:

Assertion with own exception throwing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/error.h

    r1746 r1785  
    499499
    500500
    501   inline
    502   void assert_fail(const char *file, int line, const char *func,
    503                    const char *message, const char *assertion = 0,
     501  template <typename Exception>
     502  inline void assert_fail(const char *file, int line, const char *func,
     503                   Exception exception, const char *assertion = 0,
    504504                   bool do_abort=true)
     505  {
     506    using namespace std;
     507    cerr << file << ":" << line << ": ";
     508    if( func )
     509      cerr << func << ": ";
     510    cerr << exception.what();
     511    if( assertion )
     512      cerr << " (assertion '" << assertion << "' failed)";
     513    cerr << endl;
     514    if(do_abort)
     515      abort();
     516  }
     517
     518  template <>
     519  inline void assert_fail<const char *>(const char *file, int line, const char *func,
     520                                 const char *message,
     521                                 const char *assertion,
     522                                 bool do_abort)
    505523  {
    506524    using namespace std;
     
    516534  }
    517535
    518   inline
    519   void assert_fail_throw(const char *file, int line, const char *func,
    520                    const char *message, const char *assertion = 0,
    521                    bool = true)
     536  template <typename Exception>
     537  inline void assert_fail_failure(const char *file, int line, const char *func,
     538                           Exception exception,
     539                           const char *assertion = 0,
     540                           bool = true)
     541  {
     542    throw AssertionFailedError(file, line, func, exception.what(), assertion);
     543  }
     544
     545  template <>
     546  inline void assert_fail_failure<const char *>(const char *file, int line,
     547                                         const char *func,
     548                                         const char *message,
     549                                         const char *assertion,
     550                                         bool)
    522551  {
    523552    throw AssertionFailedError(file, line, func, message, assertion);
    524553  }
    525554
     555  template <typename Exception>
     556  inline void assert_fail_exception(const char *file, int line, const char *func,
     557                             Exception exception,
     558                             const char *assertion = 0, bool = true)
     559  {
     560    throw exception;
     561  }
     562
     563  template <>
     564  inline void assert_fail_exception<const char *>(const char *file, int line,
     565                                           const char *func,
     566                                           const char *message,
     567                                           const char *assertion,
     568                                           bool)
     569  {
     570    throw AssertionFailedError(file, line, func, message, assertion);
     571  }
     572
    526573/// @}
    527574
     
    537584
    538585#ifndef LEMON_ASSERT_HANDLER
    539 #  ifdef LEMON_ASSERT_EXCEPTION
    540 #    define LEMON_ASSERT_HANDLER ::lemon::assert_fail_throw
     586#  if defined LEMON_ASSERT_EXCEPTION
     587#    define LEMON_ASSERT_HANDLER ::lemon::assert_fail_exception
     588#  elif defined LEMON_ASSERT_FAILURE
     589#    define LEMON_ASSERT_HANDLER ::lemon::assert_fail_failure
    541590#  else
    542591#    define LEMON_ASSERT_HANDLER ::lemon::assert_fail
     
    563612 *
    564613 * \todo This whole 'assert' business should be placed in a separate
    565  * include file.
     614 * include file. The boost assert is not guarded by header sentries
     615 * which may help to change the behaviour of the assertions in
     616 * the files.
    566617 *
    567618 * \todo __PRETTY_FUNCTION__ should be replaced by something
Note: See TracChangeset for help on using the changeset viewer.