在系统加载时,遇到了类似配置文件错误等问题时,你们一般怎样解决呢?
我的习惯是记录下日志,并让系统宕掉好了,当然这只是针对系统启动时,在运行期就不能这么干了
所以刚好结合上一篇的日志记录,写个断言
//=========================================================================
// FILE: [Assert]
// AUTH: Wayne.Hu
// DATE: 2014/08/09 13:42:21
// CITY: 苏州
// DESC: 断言,false时记录日志,并强制abort
//=========================================================================
#ifndef __ASSERT_2014_8_9_H__
#define __ASSERT_2014_8_9_H__
#include "TraceLog.h"
// 断言
#define Assert(exp) __AssertCheck( (exp) != 0, __FILE__, __LINE__, #exp );
inline void __AssertCheck(bool bException, const char* file, int nLine, const char* exp)
{
if (!bException)
{
TraceError("Assert failed in file [%s], line %d. Exception is [%s]", file, nLine, exp);
::abort();
}
}
#endif//__ASSERT_2014_8_9_H__
使用示例:
FILE* pF = NULL;
fopen_s(&pF, m_strName.c_str(), "a");
Assert(pF);