异常类模板

#ifndef _MY_EXCEPTION_H_ #define _MY_EXCEPTION_H_ #include <getopt.h> #include <unistd.h> #include <errno.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <dlfcn.h> #include <sys/cdefs.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <vector> #define MYEXCEP(iCode,sMsg) MyException(__FILE__,__LINE__,iCode,sMsg) #define THROW_MYEXCEP(iCode,format,...) do{ char _MYEXCEPSTR[2048]; memset(_MYEXCEPSTR , 0 , sizeof(_MYEXCEPSTR)); snprintf(_MYEXCEPSTR , sizeof(_MYEXCEPSTR) , "[%s:%d]"format , __FILE__ , __LINE__ , ##__VA_ARGS__); throw MyException(__FILE__,__LINE__,iCode,_MYEXCEPSTR); }while(0) using namespace std; class MyException { public: MyException(char *psFile , int iLine , int iCode , char *psMsg) { this->iLine = iLine; this->iCode = iCode; memset( sMsg , 0 , sizeof(sMsg) ); memset( sFile , 0 , sizeof(sFile) ); snprintf( sFile , sizeof(sFile) , "%s" , psFile ); snprintf( sMsg , sizeof(sMsg) , "%s" , psMsg ); } virtual ~MyException(){} public: int iCode ; int iLine ; char sMsg[1024] ; char sFile[128] ; }; #endif

你可能感兴趣的:(异常类模板)