- 浏览: 354091 次
- 性别:
- 来自: 苏州
文章分类
- 全部博客 (335)
- C++ (190)
- 设计模式 (43)
- 数据库技术 (5)
- 网络编程 (11)
- 自动化测试 (6)
- Linux (13)
- OpenSSL (10)
- MS Crypt API (5)
- SCM (2)
- English (4)
- Android (10)
- EMV规范 (1)
- Saturn Platform (0)
- C (10)
- SQL (2)
- ASP.NET (3)
- 英语口语学习 (3)
- 调试工具 (21)
- 编译技术 (5)
- UML (1)
- 项目管理 (5)
- 敏捷开发 (2)
- Http Server (6)
- 代码审查、代码分析 (5)
- 面试基础 (10)
- 重点知识 (16)
- STL (6)
- Efficient C++资料 (8)
- 数据结构和算法 (7)
- 读书笔记 (0)
- 开源项目 (4)
- 多线程 (2)
- Console App (6)
- 个人开源项目 (4)
- IBM DevelopWorks (4)
- Java (16)
- 内存泄漏相关调试和检测 (13)
- 软件测试相关技术 (2)
- C# (11)
- Apple Related (1)
- 软件测试和管理 (2)
- EMV (1)
- Python (1)
- Node.js (6)
- JavaScript (5)
- VUE (1)
- Frontend (1)
- Backend (4)
- RESTful API (3)
- Firebase (3)
最新评论
-
u013189503:
来个密码吧
[C++][Logging] 项目中写日志模块的实现 -
wyf_vc:
来个密码啊!!
[C++][Logging] 项目中写日志模块的实现
对于不同的项目而言,error code返回机制是不一样的,但是能够很好的管理好不同模块间的Error Code并不是一件简单的事情,下面有一种比较简便的方法如下:
One sample for this architecture, it's easy to control, isn't it? Any problems, please let me know.
/**************************************************************************************************/ /*! \file CommonErrors.h \attention (c) Jacky Dai 2011~2016 All Rights Reserved. */ /**************************************************************************************************/ #ifndef XX_COMMON_ERRORS_H #define XX_COMMON_ERRORS_H /*** Include Files ********************************************************************************/ /*** Defines/Macros/Constants/Typedefs ************************************************************/ namespace XXSpace { //basic mask code const unsigned int COMPONENT_MASK = 0x8000; //component code const unsigned int COMPONENT_LOGIN = 0x0001; const unsigned int COMPONENT_DATAMANAGER = 0x0002; // //0x0000XXXX:XXXX means component code //0xXXXX0000:XXXX means error code of component //Define some marcos/functions here #define SYSTEM_ERROR_FLAG (0x4000) #define SYSTEM_ERROR(code) ((code | SYSTEM_ERROR_FLAG) << 16) #define ERROR_IS_SYSTEM_ERROR(err) (((err >> 16) & SYSTEM_ERROR_FLAG) != 0) #define COMPONENT_ERROR(component, code) ((code << 16) | (component & ~(COMPONENT_MASK))) #define CODE_FROM_ERROR(err) (static_cast<short>(err >> 16)) //All of the error code is here typedef enum { // Hex | Decimal | Descriptio //Basic error ERR_OK = 0x00000000, //<< 0x00000000 | 0 | No error. ERR_SYSTEM = SYSTEM_ERROR(1), //<< 0x00010000 | 65536 | General system error. ERR_TIMEOUT = SYSTEM_ERROR(2), //<< 0x00020000 | 131072 | Time out. //login component LOGIN_ERROR_UNKNOWN_ERROR = COMPONENT_ERROR(COMPONENT_LOGIN, 1), //<< 0x00010001 |65537 | Unrecognized error. LOGIN_ERROR_UNKNOWN_USER_NAME = COMPONENT_ERROR(COMPONENT_LOGIN, 2), //<< 0x00020001 |131073 | Unrecognized user name, it is case sensitive. //data manager component DATAMANAGER_ERROR_UNKNOWN_ERROR = COMPONENT_ERROR(COMPONENT_DATAMANAGER, 1), //<< 0x00010002 |65538 | Unrecognized error. DATAMANAGER_ERROR_MISSING_CONNECTION = COMPONENT_ERROR(COMPONENT_DATAMANAGER, 2) //<< 0x00020002 |131074 | Connection missed. } XXCommonError; /**************************************************************************************************/ /*! \class ErrorHelper Class with commands for translating error codes to useful strings. */ /**************************************************************************************************/ class ErrorHelper { public: static const char* getErrorName(XXCommonError error); static const char* getErrorDescription(XXCommonError error); }; } // XXSpace #endif //XX_COMMON_ERRORS_H
/**************************************************************************************************/ /*! \file CommonErrors.cpp \attention (c) Jacky Dai 2011~2016 All Rights Reserved. */ /**************************************************************************************************/ /*** Include Files ********************************************************************************/ #include "CommonErrors.h" /*** Defines/Macros/Constants/Typedefs ************************************************************/ namespace XXSpace { /*** Public Methods ******************************************************************************/ const char* ErrorHelper::getErrorName(XXCommonError error) { const char* result = "UKNOWN"; switch (error) { case ERR_OK: result = "ERR_OK"; break; case ERR_SYSTEM: result = "ERR_SYSTEM"; break; case ERR_TIMEOUT: result = "ERR_TIMEOUT"; break; case LOGIN_ERROR_UNKNOWN_ERROR: result = "LOGIN_ERROR_UNKNOWN_ERROR"; break; case LOGIN_ERROR_UNKNOWN_USER_NAME: result = "LOGIN_ERROR_UNKNOWN_USER_NAME"; break; case DATAMANAGER_ERROR_UNKNOWN_ERROR: result = "DATAMANAGER_ERROR_UNKNOWN_ERROR"; break; case DATAMANAGER_ERROR_MISSING_CONNECTION: result = "DATAMANAGER_ERROR_MISSING_CONNECTION"; break; default: break; } return result; } const char* ErrorHelper::getErrorDescription(XXCommonError error) { const char *result = "UKNOWN"; switch (error) { case ERR_OK: result = "No error."; break; case ERR_SYSTEM: result = "General system error."; break; case ERR_TIMEOUT: result = "Time out."; break; case LOGIN_ERROR_UNKNOWN_ERROR: result = "Unrecognized error."; break; case LOGIN_ERROR_UNKNOWN_USER_NAME: result = "Unrecognized user name, it is case sensitive."; break; case DATAMANAGER_ERROR_UNKNOWN_ERROR: result = "Unrecognized error."; break; case DATAMANAGER_ERROR_MISSING_CONNECTION: result = "Connection missed."; break; default: break; } return result; } } // XXSpace
One sample for this architecture, it's easy to control, isn't it? Any problems, please let me know.
#include <Windows.h> #include "CommonErrors.h" #include <iostream> using namespace std; /**************************************************************************************************/ /*! \class XXStub Stub class for the XXXX. */ /**************************************************************************************************/ class Login{}; class LoginStub : public Login { public: typedef enum { ERR_OK = XXSpace::ERR_OK, ERR_SYSTEM = XXSpace::ERR_SYSTEM, ERR_TIMEOUT = XXSpace::ERR_TIMEOUT, LOGIN_ERROR_UNKNOWN_ERROR = XXSpace::LOGIN_ERROR_UNKNOWN_ERROR, LOGIN_ERROR_UNKNOWN_USER_NAME = XXSpace::LOGIN_ERROR_UNKNOWN_USER_NAME } Errors; Errors DoLogin(const char* userName, const char* password); const char* GetLoginStubErrorName(Errors error); const char* getErrorDescription(Errors error); }; LoginStub::Errors LoginStub::DoLogin(const char* userName, const char* password) { if( userName==NULL || password==NULL ) { return LOGIN_ERROR_UNKNOWN_USER_NAME; } return ERR_OK; } const char* LoginStub::GetLoginStubErrorName(Errors error) { return XXSpace::ErrorHelper::getErrorName(static_cast<XXSpace::XXCommonError>(error)); } const char* LoginStub::getErrorDescription(Errors error) { return XXSpace::ErrorHelper::getErrorDescription(static_cast<XXSpace::XXCommonError>(error)); } class DataManager{}; class DataManagerStub : public DataManager { public: typedef enum { ERR_OK = XXSpace::ERR_OK, ERR_SYSTEM = XXSpace::ERR_SYSTEM, ERR_TIMEOUT = XXSpace::ERR_TIMEOUT, DATAMANAGER_ERROR_UNKNOWN_ERROR = XXSpace::DATAMANAGER_ERROR_UNKNOWN_ERROR, DATAMANAGER_ERROR_MISSING_CONNECTION = XXSpace::DATAMANAGER_ERROR_MISSING_CONNECTION } Errors; Errors Test(); const char* GetDataManagerStubErrorName(Errors error); const char* getErrorDescription(Errors error); }; DataManagerStub::Errors DataManagerStub::Test() { return DATAMANAGER_ERROR_UNKNOWN_ERROR; } const char* DataManagerStub::GetDataManagerStubErrorName(Errors error) { return XXSpace::ErrorHelper::getErrorName(static_cast<XXSpace::XXCommonError>(error)); } const char* DataManagerStub::getErrorDescription(Errors error) { return XXSpace::ErrorHelper::getErrorDescription(static_cast<XXSpace::XXCommonError>(error)); } ////////////////////////////////////////////////////////////////////////// void main() { LoginStub cLogin; LoginStub::Errors loginError = cLogin.DoLogin(NULL, NULL); cout << hex << loginError << " = "; cout << cLogin.GetLoginStubErrorName(loginError) << endl; cout << cLogin.getErrorDescription(loginError) << endl; DataManagerStub dm; DataManagerStub::Errors dmError = dm.Test(); cout << hex << dmError << " = "; cout << dm.GetDataManagerStubErrorName(dmError) << endl; cout << dm.getErrorDescription(dmError) << endl; }
- Architecture_of_Error_Code.zip (2 KB)
- 下载次数: 10
- ErrorCodeFramework.zip (5 KB)
- 下载次数: 1
发表评论
-
FreeRTOS
2022-03-05 16:31 207Ref https://blog.csdn.net/weix ... -
串口通讯相关
2018-11-02 13:44 360https://bbs.csdn.net/wap/topics ... -
[转]C++验证IP是否可以PING通
2018-10-30 17:54 1228https://www.cnblogs.com/guoyz13 ... -
C++/MFC 換皮膚
2018-10-20 11:05 423https://blog.csdn.net/u01123991 ... -
WinCE 截屏 - C++ 代碼
2018-08-31 09:45 522// this function create a bmp ... -
Android NDK搭建環境
2017-11-27 13:25 528https://www.cnblogs.com/ut2016- ... -
8583协议相关
2017-10-17 13:38 5138583相关资料,整理中... -
Java高级应用之JNI
2017-06-19 09:00 541参考link http://www.cnblogs.com/l ... -
C++实现ping功能
2017-04-18 11:21 2028基础知识 ping的过程是向目的IP发送一个type=8的I ... -
OpenSSL 编译环境搭建
2017-03-27 15:01 8561 安裝VS2008到 c:\Program Files (x ... -
最优非对称加密填充(OAEP)
2017-03-25 14:53 1509OpenSSL命令---rsautl http://blog. ... -
[Platform Builder] 设置SVM OS build Env
2016-11-10 11:39 01 copy one OSDesign Project to ... -
[Windows] System Error Codes(GetLastError )0-----5999
2016-10-26 13:28 1833ERROR_SUCCESS 0 (0x0) T ... -
开源Windows驱动程序框架
2016-09-17 21:35 813转自 http://code.csdn.net/news/28 ... -
c/c++代码中执行cmd命令
2016-09-14 14:50 1812转自 http://blog.csdn.net/slixinx ... -
C#使用C++标准DLL实例(包含callback)
2016-09-11 19:44 1000C++编写标准Win32DLL如下 头文件 /***** ... -
C#调用C++的DLL搜集整理的所有数据类型转换方式
2016-09-09 16:07 927转自 http://www.cnblogs.com/zeroo ... -
WinCE CPU使用率计算 测试工具
2016-09-08 16:14 935转自 http://blog.csdn.net/jan ... -
switch在C++与C#中的一些差异
2016-09-08 15:19 756参考链接 http://blog.csdn.net/weiwe ... -
C++ 鼠标模拟程序
2016-09-04 12:09 1532转自 http://blog.csdn.net/weixinh ...
相关推荐
NULL 博文链接:https://jacky-dai.iteye.com/blog/2310318
博文的配套源码 《【 Visual C++】游戏开发笔记之二——最简单的directx,vc窗口的编写 》 ,原文地址为http://blog.csdn.net/zhmxy555/article/details/7318634, 源码编译环境为vs2010. 我的博客地址是...
no bugs!delivering error-free code in c & c++
The C++ Standard Library provides a set of common classes and interfaces that greatly extend the core C++ language. Josuttis' book not only provides comprehensive documentation of each library ...
博文的配套源码 《 【Visual C++】游戏开发笔记二十六 DirectX 11各组件的介绍&第一个DirectX 11 Demo的创建》 ,文章地址为http://blog.csdn.net/zhmxy555/article/details/7688515, 点击debug下的exe文件可以...
Visual Studio Code 1.69.1 (VSCodeSetup-arm64-1.69.1.exe) 适用于System Installer Windows 64位系统Arm芯片: 它是一个轻量级但功能强大的源代码编辑器,可在您的桌面上运行。它内置了对 JavaScript、TypeScript...
void onError(ErrorCode errorCode); void onProgress(int percent); void onSuccess(); void setLuaCallbacks(const std::string& callbackMap); private: std::string *_versionLoadedCallback = nullptr;...
int errorcode; /*定义错误信息*/ initgraph(&gdriver;,&gmode;,"c:\\tc30\\bgi"); /*初始化图形*/ errorcode=graphresult(); /*获取错误信息 */ if (errorcode!=grOk) /*错误发生判断*/ { printf("graphics ...
Well-written code is easier to test and reuse, simpler to parallelize, and less error prone. Mastering the functional style of programming can help you tackle the demands of modern apps and will lead ...
Complete ANSI/ISO-compatible C++ source code is included on a CD for the reader to study and re-use and so develop the skills needed to implement financial models with object-oriented programs and ...
Style Comments C++ Code Naming Style Coding Religion Indentation and Code Format Clarity Simplicity Consistency and Organization Further Reading Summary 4. Basic Declarations and Expressions Basic ...
error correct coding的iFFT,在編碼過程中的重要編碼之一,屬於是ieee 802.16裡的bpsk。
microsoft visual c++ 14.0 is required问题解决办法
C/C++轻量编辑器 vs code依赖环境 mingw 使用方法 1、将该压缩包拷贝至任意目录下,用解压缩文件解压 2、解压后,复制bin目录路径,新增系统path环境变量 3、验证 同时按下 win+r 输入CMD打开命令行 输入 g++ ...
This patch addresses a number of issues in RAD Studio 10.4, pertaining to Delphi Compiler, the RAD Studio IDE in general and the new LSP-based Code Insight in particular, plus C++ Builder Android ...
本书介绍了防止程序中包含多种错误的技术。 它还讨论了如何测试程序以查找错误。
最近在移植autosar协议栈时,经常会进入开发错误(DET)模块中,提示各种开发错误,但这些提示都是些错误码,无法...工具采用C++/Qt开发,数据库用的是Qt自带的数据库SQLite,这是一个轻型数据库。用起来还是比较容易的。
The source code is written in C++. NEAT is a method for evolving speciated neural networks of arbitrary structures and sizes. NEAT leverages the evolution of structure to make neuroevolution more ...