plibsys 0.0.5
|
Error report system. More...
Go to the source code of this file.
Typedefs | |
typedef struct PError_ | PError |
Opaque data structure for an error object. | |
Functions | |
P_LIB_API PError * | p_error_new (void) |
Initializes a new empty PError. | |
P_LIB_API PError * | p_error_new_literal (pint code, pint native_code, const pchar *message) |
Initializes a new PError with data. | |
P_LIB_API const pchar * | p_error_get_message (const PError *error) |
Gets an error message. | |
P_LIB_API pint | p_error_get_code (const PError *error) |
Gets an error code. | |
P_LIB_API pint | p_error_get_native_code (const PError *error) |
Gets a platform native error code, if any. | |
P_LIB_API PErrorDomain | p_error_get_domain (const PError *error) |
Gets an error domain. | |
P_LIB_API PError * | p_error_copy (const PError *error) |
Creates a copy of a PError object. | |
P_LIB_API void | p_error_set_error (PError *error, pint code, pint native_code, const pchar *message) |
Sets error data. | |
P_LIB_API void | p_error_set_error_p (PError **error, pint code, pint native_code, const pchar *message) |
Sets error data through a double pointer. | |
P_LIB_API void | p_error_set_code (PError *error, pint code) |
Sets an error code. | |
P_LIB_API void | p_error_set_native_code (PError *error, pint native_code) |
Sets a platform native error code. | |
P_LIB_API void | p_error_set_message (PError *error, const pchar *message) |
Sets an error message. | |
P_LIB_API void | p_error_clear (PError *error) |
Clears error data. | |
P_LIB_API void | p_error_free (PError *error) |
Frees a previously initialized error object. | |
P_LIB_API pint | p_error_get_last_system (void) |
Gets the last system native error code. | |
P_LIB_API pint | p_error_get_last_net (void) |
Gets the last network native error code. | |
P_LIB_API void | p_error_set_last_system (pint code) |
Sets the last system native error code. | |
P_LIB_API void | p_error_set_last_net (pint code) |
Sets the last network native error code. | |
Error report system.
An error report system is used to notify a caller about fatal situations during the library API invocation. Usually the sequence is as following:
Note that you should not initialize a new PError object before passing the pointer into an API call. Simply initialize it with zero and check the result after. Therefore you need to free memory if an error occurred.
Most operating systems store the last error code of the most system calls in a thread-specific variable. Moreover, Windows stores the error code of the last socket related call in a separate variable. Use p_error_get_last_system() and p_error_set_last_system() to access the last system error code, p_error_get_last_net() and p_error_set_last_net() to access the last network error code.
Definition in file perror.h.
typedef struct PError_ PError |
Clears error data.
error | PError object to clear the data for. |
Gets an error code.
error | PError object to get the code from. |
P_LIB_API PErrorDomain p_error_get_domain | ( | const PError * | error | ) |
Gets an error domain.
error | PError object to get the domain from. |
Gets the last network native error code.
Gets the last system native error code.
Gets an error message.
error | PError object to get the message from. |
Gets a platform native error code, if any.
error | PError object to get the native code from. |
P_LIB_API void p_error_set_error | ( | PError * | error, |
pint | code, | ||
pint | native_code, | ||
const pchar * | message ) |
Sets error data.
error | PError object to set the data for. |
code | Error code. |
native_code | Native error code, leave 0 to ignore. |
message | Error message. |
P_LIB_API void p_error_set_error_p | ( | PError ** | error, |
pint | code, | ||
pint | native_code, | ||
const pchar * | message ) |
Sets error data through a double pointer.
error | PError object to set the data for. |
code | Error code. |
native_code | Native error code, leave 0 to ignore. |
message | Error message. |
If error is NULL it does nothing. If error is not NULL then *error should be NULL, otherwise it does nothing. It creates a PError object, sets error data and assigns it to *error. The caller is responsible to free memory of the created object after usage.
Sets the last network native error code.
code | Error code to set. |
Sets the last system native error code.
code | Error code to set. |
Sets an error message.
error | PError object to set the message for. |
message | Error message. |