关闭

值得借鉴的 异常捕获体系 (一)

724人阅读 评论(0) 收藏 举报

//--------------------------------------------------------------------------------
//
// Filename   : Assert.h
//
//--------------------------------------------------------------------------------

#ifndef __ASSERT__H__
#define __ASSERT__H__

// include files
#include "BaseType.h"

extern int g_Command_Assert ;//控制参数,不提示Assert的对话框,直接忽略
extern int g_Command_IgnoreMessageBox ;//控制参数,跳过MyMessageBox的中断

//--------------------------------------------------------------------------------
//
//
//
//
//--------------------------------------------------------------------------------
VOID __assert__ (const CHAR* file, UINT line, const CHAR* func, const CHAR* expr) ;
VOID __assertex__ (const CHAR* file, UINT line, const CHAR* func, const CHAR* expr, const CHAR* msg) ;
VOID __assertspecial__ (const CHAR* file, UINT line, const CHAR* func, const CHAR* expr, const CHAR* msg) ;
VOID __messagebox__(const CHAR*msg ) ;
//--------------------------------------------------------------------------------
//
//
//
//
//--------------------------------------------------------------------------------
VOID __protocol_assert__ (const CHAR* file, UINT line, const CHAR* func, const CHAR* expr) ;

#if defined(NDEBUG)
 #define Assert(expr) ((VOID)0)
 #define AssertEx(expr,msg) ((VOID)0)
 #define AssertSpecial(expr,msg) ((VOID)0)
 #define MyMessageBox(msg) ((VOID)0)
#elif __LINUX__
 #define Assert(expr) {if(!(expr)){__assert__(__FILE__,__LINE__,__PRETTY_FUNCTION__,#expr);}}
 #define ProtocolAssert(expr) ((VOID)((expr)?0:(__protocol_assert__(__FILE__,__LINE__,__PRETTY_FUNCTION__,#expr),0)))
 #define AssertEx(expr,msg) {if(!(expr)){__assertex__(__FILE__,__LINE__,__PRETTY_FUNCTION__,#expr,msg);}}
 #define AssertSpecial(expr,msg) {if(!(expr)){__assertspecial__(__FILE__,__LINE__,__PRETTY_FUNCTION__,#expr,msg);}}
 #define AssertExPass(expr,msg) {if(!(expr)){__assertex__(__FILE__,__LINE__,__PRETTY_FUNCTION__,#expr,msg);}}
 #define MyMessageBox(msg) ((VOID)0)
#elif __WIN_CONSOLE__ || __WIN32__ || __WINDOWS__
 #define Assert(expr) ((VOID)((expr)?0:(__assert__(__FILE__,__LINE__,__FUNCTION__,#expr),0)))
 #define AssertEx(expr,msg) ((VOID)((expr)?0:(__assertex__(__FILE__,__LINE__,__FUNCTION__,#expr,msg),0)))
 #define AssertSpecial(expr,msg) ((VOID)((expr)?0:(__assertspecial__(__FILE__,__LINE__,__FUNCTION__,#expr,msg),0)))
 #define MyMessageBox(msg) __messagebox__(msg)
#elif __MFC__
 #define Assert(expr) ASSERT(expr)
 #define AssertEx(expr,msg) ((VOID)0)
 #define AssertSpecial(expr,msg) ((VOID)0)
 #define MyMessageBox(msg) ((VOID)0)
#endif

#endif

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:343442次
    • 积分:4110
    • 等级:
    • 排名:第7766名
    • 原创:60篇
    • 转载:115篇
    • 译文:0篇
    • 评论:25条
    最新评论