Instances of cError should allways be stored on an cErrorStack instance. Each error can have custom information that can be stored after the cError instance on a stack.

Types and Definitions



#define cNoError_ 0

Macro that defines the error code value that represents no error.


typedef bool ( *c_note_error )( cRecorder rec[static 1], cError const* err );

Type definition of a note function for an cErrorType.


struct cErrorType
   char const* desc;
   c_note_error note;
typedef struct cErrorType cErrorType;

Stores information of that all error types share. The attribute desc is a string that represents the content type, like C_ErrnoErrro for example. The note function should also be the same for all instances of a cErrorType.


struct cError
   cErrorType const* type;
   cError const* sub;
typedef struct cError cError;

Struct to store error information. A cError instance should allways exist on an cErrorStack and should have stored the custom cErrorData directly after the cError. The type value stores a s

The code allows to check and handle an error in the code. The msg attribute allows to print or log the error. The type value is a pointer to the shared cErrorType instance. The sub value can point to an sub error that triggered the error.


struct cErrorStack
   int64_t space;
   void* mem;
   cError const* err;
typedef struct cErrorStack cErrorStack;

A stack that should be used to store the cError instances with the corresponding cErrorData. The err value points to the last error that was pushed on the stack.



cErrorType const C_ErrnoError;

Stores the cErrorType instance that all errors that represent an errno error reference.


struct cErrnoErrorData
   int number;
typedef struct cErrnoErrorData cErrnoErrorData;

Stores the errno number that the error represents.




int64_t error_depth_c( cError const err* );

Counts how much cError variables are chained together..


#define write_error_c_( Rec, Err )                                             \
   write_error_c( (Rec), (Err), "" )
bool write_error_c( cRecorder rec[static 1],
                    cError const *err,
                    char const fmt[static 1] );

Writes the error into a recorder. The default format writes the error notes of all chained errors and concatenates them with ": ".



#define error_stack_c_( Size )

Allocates a byte array at the stack and assigns the memory to the error stack.


#define heap_error_stack_c_( Size )

Allocates a byte array at the heap and assigns the memory to a new created error stack.


#define make_error_stack_c_( Size, Memory )

Creates a error stack with the allready allocated memory.


int64_t count_errors_c( cErrorStack es[static 1] );

Counts how much cError variables are chained together on the stack.


void drop_error_c( cErrorStack es[static 1] );

Drops the last pushed error from the stack.


bool push_error_c( cErrorStack es[static 1],
                   cErrorType const type[static 1],
                   cErrorData const* data,
                   int64_t dataSize );

Pushes a error on the stack with the corresponding cErrorData.


void reset_error_stack_c( cErrorStack es[static 1] );

Removes all chained errors from the stack.

push error


bool push_errno_error_c( cErrorStack es[static 1], int number );

Function to push a errno error with the corresponding cErrorData on the stack.