Error handling module:
defines, initializes, frees and resets the
tests whether an
charm_errstructure is empty, and
When CHarm detects an error (e.g., an internal memory allocation failure), it properly frees all the internally allocated memory before returning back to the caller. No memory leaks should therefore occur, not even after a premature exit.
Maximum number of characters in
charm_err.msg, including the terminating null character.
Maximum number of error propagations from the function, in which the error occurred to the caller.
CHARM_ERR_MALLOC_FAILURE "Memory allocation failure."#
Message to be printed when
enumerator CHARM_FAILURE = -1#
Exit status returned when CHarm is explicitly asked to terminate the program in case it encounters an error.
Successful execution of a CHarm function.
Memory allocation failure (malloc, calloc).
Error in function input/output argument(s).
Error in file reading/writing.
Error in threads initialization by FFTW.
- enumerator CHARM_FAILURE = -1#
Allocates and initializes the
charm_errstructure using default empty values.
On success, returned is a pointer to the
charm_errstructure. On error,
void charm_err_free(charm_err *err)#
Frees the memory associated with
err. No operation is performed if
void charm_err_handler(charm_err *err, _Bool terminate)#
erris not empty, prints detailed information on the error. If
terminateis set to Boolean
1, the program subsequently terminates.
erris empty, neither an error is printed nor the program is terminated (regardless of the
Before leaving the function,
erris reset to the default empty values.
It is highly recommended to call the error handling function after every call of CHarm routines that take the
charm_errstructure as an input.
In most cases, it is created by functions from this module that return a pointer to
charm_err. Experienced users may create the structure on their own, provided that they assign correct values to its members, so that CHarm can properly understood the data in it (see the rules summarized below).
unsigned int level#
Total number of error propagations from the function in which the error was encountered back to the caller.
charm_err.fileis a pointer to a string with the name of the file in which the error was encountered;
i = 1, 2, ..., CHARM_ERR_MAX_LEVEL - 1, are file names through which the error was propagated to the caller.
unsigned int *line#
Pointer to an error message.
- unsigned int level#