Error handling
The library should never make the calling programs abort, nor perform any input/output operations. This decision has to be taken by the developer of the code calling the library.
All the functions return with an exit code, defined as
typedef int32_t qmckl_exit_code;
The exit code returns the completion status of the function to the
calling program. When a function call completed successfully,
QMCKL_SUCCESS
is returned. If one of the functions of
the library fails to complete the requested task, an appropriate
error code is returned to the program.
Here is the complete list of exit codes.
Macro | Code | Description |
---|---|---|
QMCKL_SUCCESS |
0 | 'Success' |
QMCKL_INVALID_ARG_1 |
1 | 'Invalid argument 1' |
QMCKL_INVALID_ARG_2 |
2 | 'Invalid argument 2' |
QMCKL_INVALID_ARG_3 |
3 | 'Invalid argument 3' |
QMCKL_INVALID_ARG_4 |
4 | 'Invalid argument 4' |
QMCKL_INVALID_ARG_5 |
5 | 'Invalid argument 5' |
QMCKL_INVALID_ARG_6 |
6 | 'Invalid argument 6' |
QMCKL_INVALID_ARG_7 |
7 | 'Invalid argument 7' |
QMCKL_INVALID_ARG_8 |
8 | 'Invalid argument 8' |
QMCKL_INVALID_ARG_9 |
9 | 'Invalid argument 9' |
QMCKL_INVALID_ARG_10 |
10 | 'Invalid argument 10' |
QMCKL_FAILURE |
101 | 'Failure' |
QMCKL_ERRNO |
102 | strerror(errno) |
QMCKL_INVALID_CONTEXT |
103 | 'Invalid context' |
QMCKL_ALLOCATION_FAILED |
104 | 'Allocation failed' |
QMCKL_DEALLOCATION_FAILED |
105 | 'De-allocation failed' |
QMCKL_INVALID_EXIT_CODE |
106 | 'Invalid exit code' |
The qmckl_strerror
converts an exit code into a string. The
string is assumed to be large enough to contain the error message
(typically 128 characters).
128
The text strings are extracted from the previous table.
void qmckl_string_of_error(qmckl_exit_code error, char string[128]) { char* message; switch (error) { case QMCKL_SUCCESS: message = "Success"; break; case QMCKL_INVALID_ARG_1: message = "Invalid argument 1"; break; case QMCKL_INVALID_ARG_2: message = "Invalid argument 2"; break; case QMCKL_INVALID_ARG_3: message = "Invalid argument 3"; break; case QMCKL_INVALID_ARG_4: message = "Invalid argument 4"; break; case QMCKL_INVALID_ARG_5: message = "Invalid argument 5"; break; case QMCKL_INVALID_ARG_6: message = "Invalid argument 6"; break; case QMCKL_INVALID_ARG_7: message = "Invalid argument 7"; break; case QMCKL_INVALID_ARG_8: message = "Invalid argument 8"; break; case QMCKL_INVALID_ARG_9: message = "Invalid argument 9"; break; case QMCKL_INVALID_ARG_10: message = "Invalid argument 10"; break; case QMCKL_FAILURE: message = "Failure"; break; case QMCKL_ERRNO: message = strerror(errno); break; case QMCKL_INVALID_CONTEXT: message = "Invalid context"; break; case QMCKL_ALLOCATION_FAILED: message = "Allocation failed"; break; case QMCKL_DEALLOCATION_FAILED: message = "De-allocation failed"; break; case QMCKL_INVALID_EXIT_CODE: message = "Invalid exit code"; break; } strncpy(string,message,128); }
interface subroutine qmckl_string_of_error (error, string) bind(C) use, intrinsic :: iso_c_binding integer (c_int32_t), intent(in), value :: error character, intent(out) :: string(128) end subroutine qmckl_string_of_error end interface