COIN-OR::LEMON - Graph Library

Changeset 112:d2ee5e7f00ef in lemon-main


Ignore:
Timestamp:
03/27/08 13:26:16 (17 years ago)
Author:
Peter Kovacs <kpeter@…>
Branch:
default
Phase:
public
Message:

Improvements in assert.h

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/assert.h

    r108 r112  
    116116                                const char *assertion)
    117117  {
    118     std::cerr << file << ":" << line << ": ";
    119     if (function)
    120       std::cerr << function << ": ";
    121     std::cerr << exception.what();
    122     if (assertion)
    123       std::cerr << " (assertion '" << assertion << "' failed)";
    124     std::cerr << std::endl;
     118    assert_fail_log(file, line, function, exception, assertion);
    125119    std::abort();
    126120  }
     
    130124                                const char *assertion)
    131125  {
    132     std::cerr << file << ":" << line << ": ";
    133     if (function)
    134       std::cerr << function << ": ";
    135     std::cerr << message;
    136     if (assertion)
    137       std::cerr << " (assertion '" << assertion << "' failed)";
    138     std::cerr << std::endl;
     126    assert_fail_log(file, line, function, message, assertion);
    139127    std::abort();
    140128  }
     
    145133                                const char *assertion)
    146134  {
    147     assert_fail_abort(file, line, function, message.c_str(), assertion);
     135    assert_fail_log(file, line, function, message.c_str(), assertion);
     136    std::abort();
    148137  }
    149138
     
    169158                                  const char *assertion)
    170159  {
    171     assert_fail_error(file, line, function, message.c_str(), assertion);
     160    throw AssertionFailedError(file, line, function, message.c_str(), assertion);
    172161  }
    173162
     
    193182                                    const char *assertion)
    194183  {
    195     assert_fail_exception(file, line, function, message.c_str(), assertion);
     184    throw AssertionFailedError(file, line, function, message.c_str(), assertion);
    196185  }
    197186
     
    209198  (defined(LEMON_ASSERT_EXCEPTION) ? 1 : 0) +           \
    210199  (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) > 1
    211 #error "Lemon assertion system is not set properly"
     200#error "LEMON assertion system is not set properly"
    212201#endif
    213202
     
    217206     (defined(LEMON_ASSERT_EXCEPTION) ? 1 : 0) +        \
    218207     (defined(LEMON_ASSERT_CUSTOM) ? 1 : 0) == 1 ||     \
    219      defined(LEMON_ENABLE_ASSERT)) &&                   \
     208     defined(LEMON_ENABLE_ASSERTS)) &&                  \
    220209  defined(LEMON_DISABLE_ASSERTS)
    221 #error "Lemon assertion system is not set properly"
     210#error "LEMON assertion system is not set properly"
    222211#endif
    223212
     
    257246/// \ingroup exceptions
    258247///
    259 /// \brief Macro for assertions with customizable message
    260 ///
    261 /// Macro for assertions with customizable message. 
    262 /// \param exp An expression convertible to bool. If the expression is
    263 /// false, then an assertion is raised. The concrete behaviour depends
    264 /// on the settings of the assertion system.
    265 /// \param msg A \e const \e char*, a \e const std::string& or a \e
    266 /// const \e std::exception& parameter. The variable can be used to
    267 /// provide information about the circumstances of failed assertion.
    268 ///
    269 /// The assertions are disabled in the default behaviour. You can
    270 /// enable the assertions with the following code:
     248/// \brief Macro for assertion with customizable message
     249///
     250/// Macro for assertion with customizable message. 
     251/// \param exp An expression that must be convertible to \c bool.
     252/// If it is \c false, then an assertion is raised. The concrete
     253/// behaviour depends on the settings of the assertion system.
     254/// \param msg A <tt>const char*</tt>, a <tt>const std::string&</tt> or
     255/// a <tt>const std::exception&</tt> parameter, which can be used to
     256/// provide information about the circumstances of the failed assertion.
     257///
     258/// The assertions are disabled in the default behaviour.
     259/// You can enable them with the following code:
    271260/// \code
    272261/// #define LEMON_ENABLE_ASSERTS
     
    278267/// \endcode
    279268///
    280 /// The %lemon assertion system has a wide range of customization
    281 /// properties. As default behaviour the failed assertion prints a
    282 /// short log message to the standard ouput and aborts the execution.
     269/// The LEMON assertion system has a wide range of customization
     270/// properties. As a default behaviour the failed assertion prints a
     271/// short log message to the standard error and aborts the execution.
    283272///
    284273/// The following modes can be used in the assertion system:
    285274///
    286 /// - \e LEMON_ASSERT_LOG The failed assert print a short convenient
    287 ///   error message to the standard error and continues the
    288 ///   execution.
    289 /// - \e LEMON_ASSERT_ABORT This mode is similar to the \e
    290 ///   LEMON_ASSERT_LOG, but it aborts the program. It is the default
    291 ///   operation mode when the asserts are enabled with \e
    292 ///   LEMON_ENABLE_ASSERTS.
    293 /// - \e LEMON_ASSERT_ERROR The assert throws an \ref
    294 ///   lemon::AssertionFailedError "AssertionFailedError". If the \c
    295 ///   msg parameter is an exception, then the result of the \ref
    296 ///   lemon::Exception::what() "what()" member function is passed as
    297 ///   error message.
    298 /// - \e LEMON_ASSERT_EXCEPTION If the specified \c msg is an
    299 ///   exception then it raised directly (solving that the exception
     275/// - \c LEMON_ASSERT_LOG The failed assertion prints a short log
     276///   message to the standard error and continues the execution.
     277/// - \c LEMON_ASSERT_ABORT This mode is similar to the
     278///   \c LEMON_ASSERT_LOG, but it aborts the program. It is the default
     279///   behaviour mode when the assertions are enabled with
     280///   \c LEMON_ENABLE_ASSERTS.
     281/// - \c LEMON_ASSERT_ERROR The assertion throws an
     282///   \ref lemon::AssertionFailedError "AssertionFailedError".
     283///   If the \c msg parameter is an exception, then the result of the
     284///   \ref lemon::Exception::what() "what()" member function is passed
     285///   as error message.
     286/// - \c LEMON_ASSERT_EXCEPTION If the specified \c msg is an
     287///   exception, then it raised directly (solving that the exception
    300288///   can not be thrown polymorphically), otherwise an \ref
    301289///   lemon::AssertionFailedError "AssertionFailedError" is thrown with
    302 ///   the given parameter.
    303 /// - \e LEMON_ASSERT_CUSTOM The user can define an own assertion
    304 ///   handler functions. Three overloaded functions should be defined
    305 ///   with the following parameter lists:
     290///   the given parameters.
     291/// - \c LEMON_ASSERT_CUSTOM The user can define own assertion handler
     292///   functions. Three overloaded functions should be defined with the
     293///   following parameter lists:
    306294///   \code
    307 ///     void custom_assert_handler(const char* file, int line,
    308 ///                                const char* function, const char* message, const char* expression);
    309 ///     void custom_assert_handler(const char* file, int line,
    310 ///                                const char* function, const std::string& message, const char* expression);
    311 ///     void custom_assert_handler(const char* file, int line,
    312 ///                                const char* function, const std::exception& message, const char* expression);
     295///     void custom_assert_handler(const char* file, int line, const char* function,
     296///                                const char* message, const char* assertion);
     297///     void custom_assert_handler(const char* file, int line, const char* function,
     298///                                const std::string& message, const char* assertion);
     299///     void custom_assert_handler(const char* file, int line, const char* function,
     300///                                const std::exception& message, const char* assertion);
    313301///   \endcode
    314302///   The name of the functions should be defined as the \c
     
    318306///   \endcode
    319307///   Whenever an assertion is occured, one of the custom assertion
    320 ///   handler is called with appropiate parameters.
    321 ///
    322 /// The assertion mode can be changed within one compilation unit, if
    323 /// the macros are redefined with other settings and the
    324 /// lemon/assert.h file is reincluded then the behaviour is changed
    325 /// appropiately to the new settings.
     308///   handlers is called with appropiate parameters.
     309///
     310/// The assertion mode can also be changed within one compilation unit.
     311/// If the macros are redefined with other settings and the
     312/// \ref lemon/assert.h "assert.h" file is reincluded, then the
     313/// behaviour is changed appropiately to the new settings.
    326314#  define LEMON_ASSERT(exp, msg)                                        \
    327315  (static_cast<void> (!!(exp) ? 0 : (                                   \
     
    347335
    348336#  ifndef LEMON_ASSERT_HANDLER
    349 #    define LEMON_ASSERT(exp, msg)  (static_cast<void> (0))
     337#    define LEMON_ASSERT(exp, msg)  (static_cast<void>(0))
    350338#    define LEMON_FIXME(msg) (static_cast<void>(0))
    351339#  else
Note: See TracChangeset for help on using the changeset viewer.