设为首页 加入收藏

TOP

调试秘笈之运行时的错误(一)
2013-04-24 12:13:08 】 浏览:1509
Tags:调试 秘笈 行时 错误

    二、运行时的错误

    一个可以进行安全检查的宏

    scpp_assert.h:

    [cpp]

    #ifndef __SCCP_ASSERT_H__

    #define __SCCP_ASSERT_H__

    #include "sstream"

    #ifdef SCPP_THROW_EXCEPTION_ON_BUG

    #include "exception"

    namespace scpp

    {

    class ScppAssertFailedException : public std::exception

    {

    public:

    ScppAssertFailedException(const char *file_name, unsigned line_number, const char* message);

    ~ScppAssertFailedException() throw(){};

    public:

    virtual const char * what() const throw()

    {

    return what_.c_str();

    }

    private:

    std::string what_;

    };

    }// namespace scpp

    #endif

    void SCPP_AssertErrorHandler(const char *file_name, unsigned line_number, const char *message);

    #define SCPP_ASSERT(condition, msg)                 \

    if (!(condition))                               \

    {                                               \

    std::ostringstream s;                       \

    s 《 msg;                                   \

    SCPP_AssertErrorHandler(                    \

    __FILE__, __LINE__, s.str()。c_str());   \

    }

    #ifndef _DEBUG

    #define SCPP_TEST_ASSERT_ON

    #endif // !_DEBUG

    #ifdef SCPP_TEST_ASSERT_ON

    #define SCPP_TEST_ASSERT_ON(condition, msg) SCPP_ASSERT(condition, msg)

    #else

    #define SCPP_TEST_ASSERT_ON(condition, msg) // do nothing

    #endif // !SCPP_TEST_ASSERT_ON

    #endif // !_SCCP_ASSERT_H_

    scpp_assert.cpp:

    [cpp]

    #include "stdafx.h"

    #include "scpp_assert.h"

    #include "iostream"

    #include "stdlib.h"

    #ifdef SCPP_THROW_EXCEPTION_ON_BUG

    namespace scpp

    {

    ScppAssertFailedException::ScppAssertFailedException(const char *file_name, unsigned line_number, const char* message)

   

首页 上一页 1 2 3 4 5 下一页 尾页 1/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C++模板的特化 下一篇调试秘笈-内存泄露原因

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目