Files CCore/inc/sys/SysError.h CCore/src/sys/SysError.cpp
It is assumed that the OS reports errors using error codes. These codes can be converted to text messages.
#ifndef CCore_inc_sys_SysError_h #define CCore_inc_sys_SysError_h #include <CCore/inc/Gadget.h> namespace CCore { namespace Sys { /* enum ErrorType */ enum ErrorType : .... { NoError = 0 }; /* classes */ struct ErrorDesc; /* struct ErrorDesc */ struct ErrorDesc { // public data const char *str; ulen len; // public bool init(ErrorType error,PtrLen<char> buf) noexcept; const char * getPtr() const { return str; } ulen getLen() const { return len; } }; } // namespace Sys } // namespace CCore #endif
The enumeration ErrorType represents error codes. It may have a base integral type (usually int). All target functions report errors using this enumeration.
NoError is a "no-error" code and it must be equal zero.
The structure ErrorDesc is used to convert a error code to the text message.
The fields str and len defines the text string.
init() is used to initialize the structure. The first argument is a error code. The second is a buffer to store the text message. It may or may not be used to copy a text representation of the error code. If the buffer is not used, then the text is a static text. If the buffer is not large enough, the message may be truncated or the function may fail. The return value is true in case of success.