7.1 KiB
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.
#+NAME:cases
void qmckl_string_of_error(qmckl_exit_code error, char string[<<MAX_STRING_LENGTH()>>]) {
char* message;
switch (error) {
<<cases()>>
}
strncpy(string,message,<<MAX_STRING_LENGTH()>>);
}
interface
type (c_ptr) function qmckl_string_of_error (error, string) bind(C)
use, intrinsic :: iso_c_binding
integer (c_int32_t), intent(in), value :: error
character*(<<MAX_STRING_LENTH>>), intent(out) :: string
end function qmckl_string_of_error
end interface