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]) { switch (error) { case QMCKL_SUCCESS: strncpy(string,"Success",128); break; case QMCKL_INVALID_ARG_1: strncpy(string,"Invalid argument 1",128); break; case QMCKL_INVALID_ARG_2: strncpy(string,"Invalid argument 2",128); break; case QMCKL_INVALID_ARG_3: strncpy(string,"Invalid argument 3",128); break; case QMCKL_INVALID_ARG_4: strncpy(string,"Invalid argument 4",128); break; case QMCKL_INVALID_ARG_5: strncpy(string,"Invalid argument 5",128); break; case QMCKL_INVALID_ARG_6: strncpy(string,"Invalid argument 6",128); break; case QMCKL_INVALID_ARG_7: strncpy(string,"Invalid argument 7",128); break; case QMCKL_INVALID_ARG_8: strncpy(string,"Invalid argument 8",128); break; case QMCKL_INVALID_ARG_9: strncpy(string,"Invalid argument 9",128); break; case QMCKL_INVALID_ARG_10: strncpy(string,"Invalid argument 10",128); break; case QMCKL_FAILURE: strncpy(string,"Failure",128); break; case QMCKL_ERRNO: strncpy(string,strerror(errno),128); break; case QMCKL_INVALID_CONTEXT: strncpy(string,"Invalid context",128); break; case QMCKL_ALLOCATION_FAILED: strncpy(string,"Allocation failed",128); break; case QMCKL_DEALLOCATION_FAILED: strncpy(string,"De-allocation failed",128); break; case QMCKL_INVALID_EXIT_CODE: strncpy(string,"Invalid exit code",128); break; } }
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