From 8d0095dea055c919103a7aabfc3a1b85af1feb0e Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 5 Dec 2008 20:32:09 +0000 Subject: Reformat ASSERT macro for readability. Reformat THROW_EXCEPTION macro to avoid overlong lines. Add THROW_EXCEPTION_MESSAGE macro to allow throwing an exception with a message, such as the file name that caused the exception. --- lib/common/Box.h | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'lib/common/Box.h') diff --git a/lib/common/Box.h b/lib/common/Box.h index 5929d5b8..6b50ade1 100644 --- a/lib/common/Box.h +++ b/lib/common/Box.h @@ -42,7 +42,15 @@ extern bool AssertFailuresToSyslog; #define ASSERT_FAILS_TO_SYSLOG_ON {AssertFailuresToSyslog = true;} void BoxDebugAssertFailed(const char *cond, const char *file, int line); - #define ASSERT(cond) {if(!(cond)) {BoxDebugAssertFailed(#cond, __FILE__, __LINE__); THROW_EXCEPTION(CommonException, AssertFailed)}} + #define ASSERT(cond) \ + { \ + if(!(cond)) \ + { \ + BoxDebugAssertFailed(#cond, __FILE__, __LINE__); \ + THROW_EXCEPTION_MESSAGE(CommonException, \ + AssertFailed, #cond); \ + } \ + } // Note that syslog tracing is independent of BoxDebugTraceOn, // but stdout tracing is not @@ -96,13 +104,21 @@ #define THROW_EXCEPTION(type, subtype) \ { \ OPTIONAL_DO_BACKTRACE \ - BOX_WARNING("Exception thrown: " #type "(" #subtype ") at " \ - __FILE__ "(" << __LINE__ << ")") \ + BOX_WARNING("Exception thrown: " #type "(" #subtype ") " \ + "at " __FILE__ "(" << __LINE__ << ")") \ throw type(type::subtype); \ } -// extra macros for converting to network byte order +#define THROW_EXCEPTION_MESSAGE(type, subtype, message) \ + { \ + OPTIONAL_DO_BACKTRACE \ + BOX_WARNING("Exception thrown: " #type "(" #subtype ") " \ + " (" message ") at " \ + __FILE__ "(" << __LINE__ << ")") \ + throw type(type::subtype, message); \ + } +// extra macros for converting to network byte order #ifdef HAVE_NETINET_IN_H #include #endif -- cgit v1.2.3