Functions for errors handlingΒΆ

Apart from the constructor functions (the functions returning pointers to the types defined above); all the functions return a status code, which is 0 if nothing went wrong, and another value in case of error. The following function allow for error handling from the C side.

const char * chfl_strerror(int status)

Get the error message corresponding to an error code.

Return
A null-terminated string encoding the textual representation of the status.
Parameters
  • status -

    The error code

const char * chfl_last_error(void)

Get the last error message.

Return
A null-terminated string encoding the textual representation of the last error.

int chfl_clear_errors(void)

Clear the last error message.

Return
The status code

CHFL_LOG_LEVEL enum

Available logging level.

Values:

  • CHFL_LOG_ERROR = = 0 -

    Only log on errors.

  • CHFL_LOG_WARNING = = 1 -

    Log warnings and erors.

  • CHFL_LOG_INFO = = 2 -

    Log infos, warnings and errors.

  • CHFL_LOG_DEBUG = = 3 -

    Log everything.

int chfl_loglevel(chfl_log_level_t * level)

Get the current maximal logging level.

Return
The status code
Parameters
  • level -

    The logging level

int chfl_set_loglevel(chfl_log_level_t level)

Set the current maximal logging level to level

Return
The status code
Parameters
  • level -

    The new logging level

int chfl_logfile(const char * file)

Redirect the logs to file, overwriting the file if it exists.

Return
The status code
Parameters
  • file -

    The filename for the new log file.

int chfl_log_stderr(void)

Redirect the logs to the standard error output. This is enabled by default.

Return
The status code

The return values for this status code correspond to the following macros:

CHFL_SUCCESS

Status code for success.

CHFL_MEMORY_ERROR

Memory error: out of memory, wrong size for arrays parameters, ...

CHFL_FILE_ERROR

File error: file do not exist, you do not have rights to open it, ...

CHFL_FORMAT_ERROR

Error in file formating.

CHFL_GENERIC_ERROR

Any other error from Chemfiles.

CHFL_CXX_ERROR

Error in the C++ standard library.