Defines | |
| #define | CPL_ERROR_MAX_MESSAGE_LENGTH 256 |
| The maximum length of a CPL error message. | |
| #define | CPL_HAVE_VA_ARGS 1 |
| Flag to indicate support for variadic macros. | |
| #define | cpl_error_ensure(CONDITION, CODE, ACTION,) |
| Generic error handling macro. | |
| #define | cpl_ensure(BOOL, ERRCODE, RETURN) cpl_error_ensure(BOOL, ERRCODE, return(RETURN), " ") |
| Set an error code and return iff a boolean expression is false. | |
| #define | cpl_ensure_code(BOOL, ERRCODE) cpl_error_ensure(BOOL, ERRCODE, return(cpl_error_get_code()), " ") |
| Set an error code and return it iff a boolean expression is false. | |
| #define | cpl_error_set(function, code) |
| Set CPL error code, function name, source file and line number where an error occurred. | |
| #define | cpl_error_set_where(function) |
| Propagate a CPL-error to the current location. | |
| #define | cpl_error_set_message(function, code,) |
| Set CPL error code, function name, source file and line number where an error occurred along with a text message. | |
Enumerations | |
| enum | _cpl_error_code_ { CPL_ERROR_NONE = 0, CPL_ERROR_UNSPECIFIED = 1, CPL_ERROR_DUPLICATING_STREAM, CPL_ERROR_ASSIGNING_STREAM, CPL_ERROR_FILE_IO, CPL_ERROR_BAD_FILE_FORMAT, CPL_ERROR_FILE_ALREADY_OPEN, CPL_ERROR_FILE_NOT_CREATED, CPL_ERROR_FILE_NOT_FOUND, CPL_ERROR_DATA_NOT_FOUND, CPL_ERROR_ACCESS_OUT_OF_RANGE, CPL_ERROR_NULL_INPUT, CPL_ERROR_INCOMPATIBLE_INPUT, CPL_ERROR_ILLEGAL_INPUT, CPL_ERROR_ILLEGAL_OUTPUT, CPL_ERROR_UNSUPPORTED_MODE, CPL_ERROR_SINGULAR_MATRIX, CPL_ERROR_DIVISION_BY_ZERO, CPL_ERROR_TYPE_MISMATCH, CPL_ERROR_INVALID_TYPE, CPL_ERROR_CONTINUE, CPL_ERROR_EOL } |
| Available error codes. More... | |
Functions | |
| void | cpl_error_reset (void) |
| Reset the cpl_error_code. | |
| cpl_error_code | cpl_error_get_code (void) |
| Get the last cpl_error_code set. | |
| const char * | cpl_error_get_message (void) |
| Get standard message of the current CPL error. | |
| const char * | cpl_error_get_function (void) |
| Get the function name where the last CPL error occurred. | |
| const char * | cpl_error_get_where (void) |
| Get function name, source file and line number where the last CPL error occurred. | |
| const char * | cpl_error_get_file (void) |
| Get the source code file name where the last CPL error occurred. | |
| unsigned | cpl_error_get_line (void) |
| Get the line number where the last CPL error occurred. | |
| const char * | cpl_error_get_message_default (cpl_error_code code) |
| Return the standard CPL error message of the current CPL error. | |
A cpl_error_code equal to the enumeration constant CPL_ERROR_NONE would indicate no error condition. Note, however, that the cpl_error_code is only set when an error occurs, and it is not reset by successful function calls. For this reason it may be appropriate in some cases to reset the cpl_error_code using the function cpl_error_reset(). The cpl_error_code set by a CPL function can be obtained by calling the function cpl_error_get_code(), but functions of type cpl_error_code would not only return this code directly, but would also return CPL_ERROR_NONE in case of success. Other CPL functions return zero on success, or a non-zero value to indicate a change of the cpl_error_code, while CPL functions returning a pointer would flag an error by returning a NULL.
To each cpl_error_code is associated a standard error message, that can be obtained by calling the function cpl_error_get_message(). Conventionally, no CPL function will ever display any error message, leaving to the caller the decision of how to handle a given error condition. A call to the function cpl_error_get_function() would return the name of the function where the error occurred, and the functions cpl_error_get_file() and cpl_error_get_line() would also return the name of the source file containing the function code, and the line number where the error occurred. The function cpl_error_get_where() would gather all this items together, in a colon-separated string.
#include <cpl_error.h>
|
|
Set an error code and return iff a boolean expression is false.
|
|
|
Set an error code and return it iff a boolean expression is false.
|
|
|
Value: do if (!(CONDITION)) { \ /* Evaluate exactly once using a name-space protected variable name */ \ const cpl_error_code cpl_ensure_error = (CODE); \ (void)cpl_error_set_message_macro(cpl_func, cpl_ensure_error \ ? cpl_ensure_error : \ CPL_ERROR_UNSPECIFIED, \ __FILE__, __LINE__, __VA_ARGS__); \ ACTION; \ } while (0)
#define assure(BOOL, CODE) \ cpl_error_ensure(BOOL, CODE, goto cleanup, " ") #define check(CMD) \ cpl_error_ensure((CMD, cpl_error_get_code() == CPL_ERROR_NONE), \ cpl_error_get_code(), goto cleanup, " ") #define assert(BOOL) \ cpl_error_ensure(BOOL, CPL_ERROR_UNSPECIFIED, goto cleanup, \ "Internal error, please report to " PACKAGE_BUGREPORT) or (same as above, but including printf-style error messages)
#define assure(BOOL, CODE, ...) \ cpl_error_ensure(BOOL, CODE, goto cleanup, __VA_ARGS__) #define check(CMD, ...) \ cpl_error_ensure((CMD, cpl_error_get_code() == CPL_ERROR_NONE), \ cpl_error_get_code(), goto cleanup, __VA_ARGS__) #define assert(BOOL, ...) \ cpl_error_ensure(BOOL, CPL_ERROR_UNSPECIFIED, goto cleanup, \ "Internal error, please report to " PACKAGE_BUGREPORT \ " " __VA_ARGS__) / * Assumes that PACKAGE_BUGREPORT contains no formatting special characters * / or
#define skip_if(BOOL) \ cpl_error_ensure(BOOL, cpl_error_get_code() != CPL_ERROR_NONE ? \ cpl_error_get_code() : CPL_ERROR_UNSPECIFIED, \ goto cleanup, " ") The check macros in the examples above can be used to check a command which sets the cpl_error_code in case of failure (or, by use of a comma expression, a longer sequence of such commands): check(
(x = cpl_table_get_int(table, "x", 0, NULL),
y = cpl_table_get_int(table, "y", 0, NULL),
z = cpl_table_get_int(table, "z", 0, NULL)),
"Error reading wavelength catalogue");
|
|
|
The maximum length of a CPL error message.
|
|
|
Set CPL error code, function name, source file and line number where an error occurred.
|
|
|
Set CPL error code, function name, source file and line number where an error occurred along with a text message.
if (image == NULL) { return cpl_error_set_message(cpl_func, CPL_ERROR_NULL_INPUT, "Image number %d is NULL", number); } |
|
|
Propagate a CPL-error to the current location.
In a function of type cpl_error_code an error can be propagated with: return cpl_error_set_where(cpl_func); |
|
|
Flag to indicate support for variadic macros.
|
|
|
Available error codes.
All error codes are guaranteed to be less than
const int my_first_error_code = 0 + CPL_ERROR_EOL; const int my_second_error_code = 1 + CPL_ERROR_EOL; const int my_third_error_code = 2 + CPL_ERROR_EOL; if (is_connected() == CPL_FALSE) { return cpl_error_set_message(cpl_func, my_first_error_code, "No " "connection to host %s (after %u tries)", hostname, max_attempts); } Extensive use of user defined error codes should be avoided. Instead a request of new CPL error codes should be emailed to cpl-help@eso.org.
|
|
|
Get the last cpl_error_code set.
|
|
|
Get the source code file name where the last CPL error occurred.
|
|
|
Get the function name where the last CPL error occurred.
|
|
|
Get the line number where the last CPL error occurred.
|
|
|
Get standard message of the current CPL error.
CPL_ERROR_NONE, an empty string is returned. |
|
|
Return the standard CPL error message of the current CPL error.
|
|
|
Get function name, source file and line number where the last CPL error occurred.
function_name:source_file:line_number |
|
|
Reset the cpl_error_code.
CPL_ERROR_NONE. |
1.3.9.1