📄 syserr.h
字号:
// syserr.h// error-reporting exception for system calls that fail// copyright SafeTP Development Group, Inc., 2000 Terms of use are as specified in license.txt// The intent here is to provide a way for portable *handling* of errors// that are generated by nonportable code.#ifndef __SYSERR_H#define __SYSERR_H#include "exc.h" // xBaseclass xSysError : public xBase {private: // data // error strings for Reasons static char const * const reasonStrings[];public: // data // portable failure reasons (modelled loosely on errno.h) // it is anticipated that, as certain errors become important on certain // platforms, that this list will be extended as necessary enum Reason { R_NO_ERROR, // no error occurred R_FILE_NOT_FOUND, R_PATH_NOT_FOUND, R_ACCESS_DENIED, R_OUT_OF_MEMORY, R_SEGFAULT, // invalid address / pointer R_FORMAT, // bad data format R_INVALID_ARGUMENT, R_READ_ONLY, R_ALREADY_EXISTS, R_AGAIN, // resource temporarily unavailable R_BUSY, // resource busy R_UNKNOWN, // OS-specific, can't find out, just don't know, etc. NUM_REASONS // (must be last item in list) } reason; // portable failure reason string char const * const reasonString; // nonportable error code (errno on Unix, GetLastError() on Windows) // (value is 0 when we don't have this information) int sysErrorCode; // name of syscall or API function name string syscallName; // error context; what was being done (e.g., "opening an.important.file") string context;public: // funcs xSysError(Reason r, char const *syscall, char const *ctx); xSysError(xSysError const &obj); ~xSysError(); // mapping functions used internally static int getSystemErrorCode(); // retrieve the error code used by local convention // [nonportable implementation] static Reason portablize(int sysErrorCode); // return a portable equivalent of a system error code // (returns R_UNKNOWN if the code is esoteric or invalid) // [nonportable implementation] static char const *getReasonString(Reason r); // translate a Reason into a string (if r is invalid, a string // saying to will be returned) static string constructWhyString(Reason r, char const *syscall, char const *ctx); // construct the string we throw as the 'why' of xBase; if ctx is NULL, // the string doesn't include it static void xsyserror(char const *syscallName, char const *context); // does the throw};// function that does the throwinline void xsyserror(char const *syscallName, char const *context = NULL){ xSysError::xsyserror(syscallName, context);}// get a representative string, for logging etc.string sysErrorCodeString(int systemErrorCode, char const *syscallName, char const *context=NULL);inline string sysErrorString(char const *syscallName, char const *context=NULL){ return sysErrorCodeString(xSysError::getSystemErrorCode(), syscallName, context);}#endif // __SYSERR_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -