JWS C Library
C language utility library
|
Declarations of an Error and associated functions. More...
#include <jwsc/config.h>
#include <stdlib.h>
#include <inttypes.h>
Go to the source code of this file.
Data Structures | |
struct | Error |
Error structure used for error handling. More... | |
Defines | |
#define | JWSC_EARG(msg) create_error(ERROR_INV_ARG, __FILE__, __LINE__, msg) |
Creates a new error caused by invalid argument. | |
#define | JWSC_EIO(msg) create_error(ERROR_IO, __FILE__, __LINE__, msg) |
Creates a new error caused by invalid I/O. | |
#define | JWSC_ECALC(msg) create_error(ERROR_CALC, __FILE__, __LINE__, msg) |
Creates a new error caused by a calculation. | |
Enumerations | |
enum | Error_type { ERROR_NO_MEMORY, ERROR_IO, ERROR_INV_ARG, ERROR_CALC, ERROR_NOT_READY, ERROR_SOCKET, ERROR_CONNECT } |
Error types. More... | |
Functions | |
Error * | create_error (Error_type type, const char *file, unsigned int line, const char *msg) |
Creates a new Error. | |
void | free_error (Error *e) |
Frees an Error. | |
void | print_error (const char *prefix, const Error *e) |
Prints an Error on stderr. | |
void | print_error_exit (const char *prefix, const Error *e) |
Prints an Error on stderr and exits. | |
void | print_error_msg (const char *prefix, const char *msg) |
Prints an error message on stderr. | |
void | print_error_msg_exit (const char *prefix, const char *msg) |
Prints an error message on stderr and exits. | |
void | print_errno (const char *prefix) |
Prints the error message associated with the current value of errno on stderr. | |
void | print_errno_exit (const char *prefix) |
Prints the error message associated with the current value of errno on stderr and exits. | |
uint32_t | get_num_unhandled_errors () |
Returns the number of errors created and never handled (freed). | |
Variables | |
Error * | error_no_memory |
Special Error for memory allocation errors. |
Declarations of an Error and associated functions.
Definition in file error.h.
#define JWSC_EARG | ( | msg | ) | create_error(ERROR_INV_ARG, __FILE__, __LINE__, msg) |
#define JWSC_EIO | ( | msg | ) | create_error(ERROR_IO, __FILE__, __LINE__, msg) |
#define JWSC_ECALC | ( | msg | ) | create_error(ERROR_CALC, __FILE__, __LINE__, msg) |
enum Error_type |
Error types.
ERROR_NO_MEMORY |
No memory available. |
ERROR_IO |
Input/output problem. |
ERROR_INV_ARG |
Argument is not in valid range. |
ERROR_CALC |
Calculated value outside error tolerance. |
ERROR_NOT_READY |
Non-blocking Result is not yet ready. |
ERROR_SOCKET |
Error creating a socket. |
ERROR_CONNECT |
Error connecting a socket. |
Error* create_error | ( | Error_type | type, |
const char * | file, | ||
unsigned int | line, | ||
const char * | msg | ||
) |
Creates a new Error.
Any and all of the const char* parameters can be NULL. If non-NULL, a copy of the the const char* parameters is allocated. The Error::code is set to 0.
type | Error_type. |
file | File where the Error occurred. |
line | Line near the offending code. |
msg | Message for the Error. |
void free_error | ( | Error * | e | ) |
void print_error | ( | const char * | prefix, |
const Error * | e | ||
) |
void print_error_exit | ( | const char * | prefix, |
const Error * | e | ||
) |
void print_error_msg | ( | const char * | prefix, |
const char * | msg | ||
) |
Prints an error message on stderr.
Prints the Error in the format
'prefix: msg\n'
If prefix == NULL, just the error message is printed. If msg is NULL, no new-line is printed. This is useful for printing multi-prefixed error messages.
prefix | Prefix to print before the error message. |
msg | Error message to print. |
void print_error_msg_exit | ( | const char * | prefix, |
const char * | msg | ||
) |
Prints an error message on stderr and exits.
Prints the Error in the format
'prefix: msg\n'
If prefix == NULL, just the error message is printed. If msg is NULL, no new-line is printed. This is useful for printing multi-prefixed error messages.
The exit status is EXIT_FAILURE.
prefix | Prefix to print before the error message. |
msg | Error message to print. |
void print_errno | ( | const char * | prefix | ) |
Prints the error message associated with the current value of errno on stderr.
Prints the Error in the format
'prefix: errno_msg\n'
The standard function strerror is used to get the message for errno.
If prefix == NULL, just the error message is printed.
prefix | Prefix to print before the error message. |
void print_errno_exit | ( | const char * | prefix | ) |
Prints the error message associated with the current value of errno on stderr and exits.
Prints the Error in the format
'prefix: errno_msg\n'
The standard function strerror is used to get the message for errno.
If prefix == NULL, just the error message is printed.
The exit status is EXIT_FAILURE.
prefix | Prefix to print before the error message. |
uint32_t get_num_unhandled_errors | ( | ) |