/** * @file WException.h * @brief 异常基类 * @author 沙漠乌鸦 * @time 2010-07-23 */ #pragma once #include #include #include #pragma warning(disable : 4290) // disable Exception Specification warning namespace wuya { // 定义获取当前文件名、当前行的宏 #define LOCATION WLocation(__FILE__, __LINE__) inline std::string WLocation(std::string strFile,int iLineNo) { const int bufSize = 64; char buf[bufSize]; sprintf_s(buf,bufSize,"Line no. %d", iLineNo); return strFile + buf; } /** @brief 基础异常函数 */ class WException : public std::runtime_error { public: WException() throw() : runtime_error("error") {} WException(std::string msg) throw() : runtime_error(msg) {} WException(std::string msg, std::string location) throw() : std::runtime_error(msg + location) {} void WriteLog(std::ostream& os) throw() { os << what() << std::endl; } }; }