error

Overview

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

error

cNoError_

#define cNoError_ 0

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

c_note_error

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

Type definition of a note function for an cErrorType.

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.

cError

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.

cErrorStack

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.

errno

C_ErrnoError

cErrorType const C_ErrnoError;

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

cErrnoErrorData

struct cErrnoErrorData
{
   int number;
};
typedef struct cErrnoErrorData cErrnoErrorData;

Stores the errno number that the error represents.

Functions

error

error_depth_c

int64_t error_depth_c( cError const err* );

Counts how much cError variables are chained together..

write_error_c

#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 ": ".

stack

error_stack_c_

#define error_stack_c_( Size )

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

heap_error_stack_c_

#define heap_error_stack_c_( Size )

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

make_error_stack_c_

#define make_error_stack_c_( Size, Memory )

Creates a error stack with the allready allocated memory.

count_errors_c

int64_t count_errors_c( cErrorStack es[static 1] );

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

drop_error_c

void drop_error_c( cErrorStack es[static 1] );

Drops the last pushed error from the stack.

push_error_c

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.

reset_error_stack_c

void reset_error_stack_c( cErrorStack es[static 1] );

Removes all chained errors from the stack.

push error

push_errno_error_c

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

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