JWS C Library
C language utility library
|
Definitions of an Error and associated functions. More...
#include <jwsc/config.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <assert.h>
#include <inttypes.h>
#include "jwsc/base/error.h"
Go to the source code of this file.
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 | |
static uint32_t | num_unhandled_errors = 0 |
Number of errors created and not handled (freed). | |
static Error | no_memory |
Used for special memory Exception. | |
Error * | error_no_memory = &no_memory |
Special Error for memory allocation errors. |
Definitions of an Error and associated functions.
Definition in file error.c.
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 | ( | ) |
uint32_t num_unhandled_errors = 0 [static] |
{ ERROR_NO_MEMORY, "No memory available.", NULL, 0, 0 }
Used for special memory Exception.