Ignore:
Timestamp:
05/12/2008 20:32:09 (3 years ago)
Author:
chris
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/lib/common/Box.h

    r2169 r2398  
    4343        #define ASSERT_FAILS_TO_SYSLOG_ON {AssertFailuresToSyslog = true;} 
    4444        void BoxDebugAssertFailed(const char *cond, const char *file, int line); 
    45         #define ASSERT(cond) {if(!(cond)) {BoxDebugAssertFailed(#cond, __FILE__, __LINE__); THROW_EXCEPTION(CommonException, AssertFailed)}} 
     45        #define ASSERT(cond) \ 
     46        { \ 
     47                if(!(cond)) \ 
     48                { \ 
     49                        BoxDebugAssertFailed(#cond, __FILE__, __LINE__); \ 
     50                        THROW_EXCEPTION_MESSAGE(CommonException, \ 
     51                                AssertFailed, #cond); \ 
     52                } \ 
     53        } 
    4654 
    4755        // Note that syslog tracing is independent of BoxDebugTraceOn, 
     
    97105        { \ 
    98106                OPTIONAL_DO_BACKTRACE \ 
    99                 BOX_WARNING("Exception thrown: " #type "(" #subtype ") at " \ 
    100                         __FILE__ "(" << __LINE__ << ")") \ 
     107                BOX_WARNING("Exception thrown: " #type "(" #subtype ") " \ 
     108                        "at " __FILE__ "(" << __LINE__ << ")") \ 
    101109                throw type(type::subtype); \ 
    102110        } 
    103111 
     112#define THROW_EXCEPTION_MESSAGE(type, subtype, message) \ 
     113        { \ 
     114                OPTIONAL_DO_BACKTRACE \ 
     115                BOX_WARNING("Exception thrown: " #type "(" #subtype ") " \ 
     116                        " (" message ") at " \ 
     117                        __FILE__ "(" << __LINE__ << ")") \ 
     118                throw type(type::subtype, message); \ 
     119        } 
     120 
    104121// extra macros for converting to network byte order 
    105  
    106122#ifdef HAVE_NETINET_IN_H 
    107123        #include <netinet/in.h> 
Note: See TracChangeset for help on using the changeset viewer.