file
Error.hThis module provides an extensible type for communicating errors via both error codes and message strings.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Classes
Typedefs
Functions
-
Trait(CnxErrorCategory,
const_
cstring(*)(const CnxErrorCategory*restrict self, i64 code) message;i64(*)(const CnxErrorCategory*restrict self) get_last_error;) CnxErrorCategory
is aTrait
that provides the mechanism to convert an arbitrary error code into a corresponding message associated with a specific class of errors, and to get the last error that occurred in a particular category (if supported by the category. For example, global categories likeCNX_WIN32_ERROR_CATEGORY
andCNX_POSIX_ERROR_CATEGORY
support this, but categories local to specific modules probably won't).- CnxError cnx_error_new(i64 error_code, CnxErrorCategory error_category)
- Creates a
CnxError
with the given error code and category. - i64 cnx_error_code(const CnxError*restrict self)
- Returns the error code associated with the given error.
-
const_
cstring cnx_error_message(const CnxError*restrict self) - Returns the error message associated with the given error, as a
cstring
-
const_
cstring cnx_error_category_get_message(CnxErrorCategory self, i64 error_code) - Returns the error message associated with the given error code, as a
cstring
- i64 cnx_error_category_get_last_error(CnxErrorCategory self)
- Returns the error code for the last reported error.
-
const_
cstring cnx_posix_category_get_message(const CnxErrorCategory*restrict self, i64 error_code) - Returns the POSIX error message associated with the given error code, as a
cstring
- i64 cnx_posix_category_get_last_error(const CnxErrorCategory*restrict self)
- Returns the error code for the last reported POSIX error.
- CnxFormatContext cnx_error_is_specifier_valid(const CnxFormat*restrict self, CnxStringView specifier)
- Implementation of
CnxFormat.is_specifier_valid
forCnxError
- CnxString cnx_error_format(const CnxFormat*restrict self, CnxFormatContext context)
- Implementation of
CnxFormat.format
forCnxError
- CnxString cnx_error_format_with_allocator(const CnxFormat*restrict self, CnxFormatContext context, CnxAllocator allocator)
- Implementation of
CnxFormat.format_with_allocator
forCnxError
-
static ImplTraitFor(CnxFormat,
CnxError,
cnx_
error_ is_ specifier_ valid, cnx_ error_ format, cnx_ error_ format_ with_ allocator) - Implement
CnxFormat
forCnxError
Defines
- #define CNX_ERROR
- Declarations and definitions related to
CnxError
- #define CNX_POSIX_ERROR_CATEGORY
- The
CnxErrorCategory
to map POSIX error codes. - #define CNX_DEFAULT_ERROR_CATEGORY
- the default
CnxErrorCategory
. By default, this isCNX_POSIX_ERROR_CATEGORY
Function documentation
CnxFormatContext cnx_error_is_specifier_valid(const CnxFormat*restrict self, CnxStringView specifier)
Implementation of CnxFormat.is_specifier_valid
for CnxError
Parameters | |
---|---|
self | - The CnxError to format as a CnxFormat trait object |
specifier | - The CnxStringView viewing the format specifier to validate |
Returns | The CnxFormatContext indicating whether specifier was valid and storing the state holding the format settings and necessary info to format the CnxError |
CnxString cnx_error_format(const CnxFormat*restrict self, CnxFormatContext context)
Implementation of CnxFormat.format
for CnxError
Parameters | |
---|---|
self | - The CnxError to format as a CnxFormat trait object |
context | - The CnxFormatContext specifying how formatting should be done |
Returns | self formatted as a CnxString |
CnxString cnx_error_format_with_allocator(const CnxFormat*restrict self, CnxFormatContext context, CnxAllocator allocator)
Implementation of CnxFormat.format_with_allocator
for CnxError
Parameters | |
---|---|
self | - The CnxError to format as a CnxFormat trait object |
context | - The CnxFormatContext specifying how formatting should be done |
allocator | - The CnxAllocator to allocate the formatted string with |
Returns | self formatted as a CnxString |