summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2008-12-05 20:32:09 +0000
committerChris Wilson <chris+github@qwirx.com>2008-12-05 20:32:09 +0000
commit8d0095dea055c919103a7aabfc3a1b85af1feb0e (patch)
tree461dbe702770ac0b79c7b41ba73ef62ce27b77f0
parentbb6f71b7213c1e2f7353b2870a2343b5e4128317 (diff)
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.
-rw-r--r--lib/common/Box.h24
1 files changed, 20 insertions, 4 deletions
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 <netinet/in.h>
#endif