[Lemon-commits] [lemon_svn] deba: r2323 - hugo/trunk/lemon
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:51:48 CET 2006
Author: deba
Date: Thu Nov 10 13:40:58 2005
New Revision: 2323
Modified:
hugo/trunk/lemon/error.h
Log:
Assertion with own exception throwing
Modified: hugo/trunk/lemon/error.h
==============================================================================
--- hugo/trunk/lemon/error.h (original)
+++ hugo/trunk/lemon/error.h Thu Nov 10 13:40:58 2005
@@ -498,15 +498,33 @@
/**************** Macros ****************/
- inline
- void assert_fail(const char *file, int line, const char *func,
- const char *message, const char *assertion = 0,
+ template <typename Exception>
+ inline void assert_fail(const char *file, int line, const char *func,
+ Exception exception, const char *assertion = 0,
bool do_abort=true)
{
using namespace std;
cerr << file << ":" << line << ": ";
if( func )
cerr << func << ": ";
+ cerr << exception.what();
+ if( assertion )
+ cerr << " (assertion '" << assertion << "' failed)";
+ cerr << endl;
+ if(do_abort)
+ abort();
+ }
+
+ template <>
+ inline void assert_fail<const char *>(const char *file, int line, const char *func,
+ const char *message,
+ const char *assertion,
+ bool do_abort)
+ {
+ using namespace std;
+ cerr << file << ":" << line << ": ";
+ if( func )
+ cerr << func << ": ";
cerr << message;
if( assertion )
cerr << " (assertion '" << assertion << "' failed)";
@@ -515,10 +533,39 @@
abort();
}
- inline
- void assert_fail_throw(const char *file, int line, const char *func,
- const char *message, const char *assertion = 0,
- bool = true)
+ template <typename Exception>
+ inline void assert_fail_failure(const char *file, int line, const char *func,
+ Exception exception,
+ const char *assertion = 0,
+ bool = true)
+ {
+ throw AssertionFailedError(file, line, func, exception.what(), assertion);
+ }
+
+ template <>
+ inline void assert_fail_failure<const char *>(const char *file, int line,
+ const char *func,
+ const char *message,
+ const char *assertion,
+ bool)
+ {
+ throw AssertionFailedError(file, line, func, message, assertion);
+ }
+
+ template <typename Exception>
+ inline void assert_fail_exception(const char *file, int line, const char *func,
+ Exception exception,
+ const char *assertion = 0, bool = true)
+ {
+ throw exception;
+ }
+
+ template <>
+ inline void assert_fail_exception<const char *>(const char *file, int line,
+ const char *func,
+ const char *message,
+ const char *assertion,
+ bool)
{
throw AssertionFailedError(file, line, func, message, assertion);
}
@@ -536,8 +583,10 @@
#endif
#ifndef LEMON_ASSERT_HANDLER
-# ifdef LEMON_ASSERT_EXCEPTION
-# define LEMON_ASSERT_HANDLER ::lemon::assert_fail_throw
+# if defined LEMON_ASSERT_EXCEPTION
+# define LEMON_ASSERT_HANDLER ::lemon::assert_fail_exception
+# elif defined LEMON_ASSERT_FAILURE
+# define LEMON_ASSERT_HANDLER ::lemon::assert_fail_failure
# else
# define LEMON_ASSERT_HANDLER ::lemon::assert_fail
# endif
@@ -562,7 +611,9 @@
* shouldn't we?
*
* \todo This whole 'assert' business should be placed in a separate
- * include file.
+ * include file. The boost assert is not guarded by header sentries
+ * which may help to change the behaviour of the assertions in
+ * the files.
*
* \todo __PRETTY_FUNCTION__ should be replaced by something
* compiler-independent, like BOOST_CURRENT_FUNCTION
More information about the Lemon-commits
mailing list