⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nlexception.h

📁 一些unix下的c/c++的util包
💻 H
字号:
/**
 * nlkit异常类的定义
 * @file NLException.h
 * @date 01-Sep-2006
 * @author 胡春雨
 * @version 1.0.0: 初始版本
 */

#ifndef _NL_EXCEPTION_HPP
#define _NL_EXCEPTION_HPP

#include <stdexcept>
#include <string>
#include <iosfwd>


/**
 * @namespace nlkit
 * @brief 新大陆工具名字空间
 */
namespace nlkit
{

/**
 * NL异常类定义
 */
class NLException : public std::logic_error
{
public:    
    /**
     * 
     * @param file 
     * @param line 
     * @param msg 
     * @return 
     */
    NLException(const char* file, int line, const std::string& msg)
        : std::logic_error("NLException"), m_file(file), m_line(line), m_msg(msg)
    {
    }

	/**
	 * 构造函数
	 * @param msg:	异常信息
	 * @return 无
	 */
	NLException(const char* file, int line, const char* msg)
		: std::logic_error("NLException"), m_file(file), m_line(line), m_msg(msg)
	{
	}

	/**
	 * 虚拟析构函数
	 * @param 无
	 * @return 无
	 */
	virtual ~NLException() throw() {}

public:

	/**
	 * 描述
	 * @param 无
	 * @return string:	描述信息
	 */
	virtual const char* what() const throw()
	{
        return m_msg.c_str(); 
    }

    virtual const char* name() const {return "nlkit::NLException"; }

    const char* throwFile() const {return m_file;}
    int throwLine() const {return m_line;}

    virtual void print(std::ostream& os) const;

protected: 
    const char* m_file;
    int m_line;
    std::string m_msg;

};	// !class NLException

std::ostream& operator<<(std::ostream& out, const NLException& ex);

// ---------------------------------------------------------------------------
//  This macros is used to actually throw an exception. It is used in order   
//  to make sure that source code line/col info is stored correctly, and to   
//  give flexibility for other stuff in the future.                           
// ---------------------------------------------------------------------------

#define THROW_EXCEPTION(type,msg) throw type(__FILE__, __LINE__, msg)                             
                                                                                             
#define THROW_EXCEPTION1(type,msg,p1) throw type(__FILE__, __LINE__, msg, p1)                     
                                                                                             
#define THROW_EXCEPTION2(type,msg,p1,p2) throw type(__FILE__, __LINE__, msg, p1, p2)              
                                                                                             
#define THROW_EXCEPTION3(type,msg,p1,p2,p3) throw type(__FILE__, __LINE__, msg, p1, p2, p3)       
                                                                                             
#define THROW_EXCEPTION4(type,msg,p1,p2,p3,p4) throw type(__FILE__, __LINE__, msg, p1, p2, p3, p4)


}	// !namespace nlkit

#endif  // !_NL_EXCEPTION_HPP

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -