14#ifndef CPL_ERROR_H_INCLUDED
15#define CPL_ERROR_H_INCLUDED
72#ifdef STRICT_CPLERRORNUM_TYPE
108#define CPLE_AppDefined 1
110#define CPLE_OutOfMemory 2
114#define CPLE_OpenFailed 4
116#define CPLE_IllegalArg 5
118#define CPLE_NotSupported 6
120#define CPLE_AssertionFailed 7
122#define CPLE_NoWriteAccess 8
124#define CPLE_UserInterrupt 9
126#define CPLE_ObjectNull 10
132#define CPLE_HttpResponse 11
134#define CPLE_BucketNotFound 12
136#define CPLE_ObjectNotFound 13
138#define CPLE_AccessDenied 14
140#define CPLE_InvalidCredentials 15
142#define CPLE_SignatureDoesNotMatch 16
144#define CPLE_ObjectStorageGenericError 17
154#define CPLE_AWSBucketNotFound CPLE_BucketNotFound
160#define CPLE_AWSObjectNotFound CPLE_ObjectNotFound
166#define CPLE_AWSAccessDenied CPLE_AccessDenied
172#define CPLE_AWSInvalidCredentials CPLE_InvalidCredentials
178#define CPLE_AWSSignatureDoesNotMatch CPLE_SignatureDoesNotMatch
184#define CPLE_AWSError CPLE_ObjectStorageGenericError
190#ifdef GDAL_COMPILATION
200#define CPLErrorOnce(eErrClass, err_no, ...) \
203 static bool lbCPLErrorOnce = false; \
204 if (!lbCPLErrorOnce) \
206 lbCPLErrorOnce = true; \
207 const char *lCPLErrorMsg = CPLSPrintf(__VA_ARGS__); \
208 const size_t lCPLErrorMsgLen = strlen(lCPLErrorMsg); \
209 const char *lCPLErrorMsgSuffix = \
210 " Further messages of this type will be suppressed."; \
211 if (lCPLErrorMsgLen && lCPLErrorMsg[lCPLErrorMsgLen - 1] == '.') \
212 CPLError((eErrClass), (err_no), "%s%s", lCPLErrorMsg, \
213 lCPLErrorMsgSuffix); \
215 CPLError((eErrClass), (err_no), "%s.%s", lCPLErrorMsg, \
216 lCPLErrorMsgSuffix); \
231#if defined(GDAL_COMPILATION) && defined(__cplusplus)
236 const GUInt32 *pnErrorCounter);
243void CPL_DLL CPLCleanupErrorMutex(
void);
269#ifdef WITHOUT_CPLDEBUG
270#define CPLDebug(...) \
274#define CPLDebugProgress(...) \
279#ifdef GDAL_COMPILATION
285#define CPLDebugOnce(...) \
297#ifdef GDAL_COMPILATION
303#define CPLDebugOnce(category, ...) \
306 static bool lbCPLDebugOnce = false; \
307 if (!lbCPLDebugOnce) \
309 lbCPLDebugOnce = true; \
310 const char *lCPLDebugMsg = CPLSPrintf(__VA_ARGS__); \
311 const size_t lCPLErrorMsgLen = strlen(lCPLDebugMsg); \
312 const char *lCPLDebugMsgSuffix = \
313 " Further messages of this type will be suppressed."; \
314 if (lCPLErrorMsgLen && lCPLDebugMsg[lCPLErrorMsgLen - 1] == '.') \
315 CPLDebug((category), "%s%s", lCPLDebugMsg, \
316 lCPLDebugMsgSuffix); \
318 CPLDebug((category), "%s.%s", lCPLDebugMsg, \
319 lCPLDebugMsgSuffix); \
326#if defined(DEBUG) || defined(GDAL_DEBUG)
330#define CPLDebugOnly(...) CPLDebug(__VA_ARGS__)
335#define CPLDebugOnly(...) \
341void CPL_DLL CPL_STDCALL
_CPLAssert(
const char *,
const char *,
344#if defined(DEBUG) && !defined(CPPCHECK)
346#define CPLAssert(expr) \
347 ((expr) ? (void)(0) : _CPLAssert(#expr, __FILE__, __LINE__))
350#define CPLAssertAlwaysEval(expr) CPLAssert(expr)
353#define CPLAssert(expr) \
360#define CPLAssertAlwaysEval(expr) CPL_IGNORE_RET_VAL(expr)
364#define CPLAssertAlwaysEval(expr) (void)(expr)
375#define VALIDATE_POINTER_ERR CE_Fatal
377#define VALIDATE_POINTER_ERR CE_Failure
382#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
389 template <
class T> T *CPLAssertNotNull(T *x)
411 CPLPushErrorHandler(hHandler);
419 CPLPushErrorHandlerEx(hHandler, user_data);
425 CPLPopErrorHandler();
436 std::string m_osLastErrorMsg;
438 std::unique_ptr<CPLErrorHandlerPusher> m_poErrorHandlerPusher;
460 CPLTurnFailureIntoWarning(
true);
465 CPLTurnFailureIntoWarning(
false);
470#ifdef GDAL_COMPILATION
473bool CPLIsDefaultErrorHandlerAndCatchDebug();
480#define VALIDATE_POINTER0(ptr, func) \
483 if (CPL_NULLPTR == ptr) \
485 CPLErr const ret = VALIDATE_POINTER_ERR; \
486 CPLError(ret, CPLE_ObjectNull, \
487 "Pointer \'%s\' is NULL in \'%s\'.\n", #ptr, (func)); \
493#define VALIDATE_POINTER1(ptr, func, rc) \
496 if (CPL_NULLPTR == ptr) \
498 CPLErr const ret = VALIDATE_POINTER_ERR; \
499 CPLError(ret, CPLE_ObjectNull, \
500 "Pointer \'%s\' is NULL in \'%s\'.\n", #ptr, (func)); \
Class that installs a (thread-local) error handler on construction, and restore the initial one on de...
Definition cpl_error.h:404
CPLErrorHandlerPusher(CPLErrorHandler hHandler)
Constructor that installs a thread-local temporary error handler (typically CPLQuietErrorHandler)
Definition cpl_error.h:409
CPLErrorHandlerPusher(CPLErrorHandler hHandler, void *user_data)
Constructor that installs a thread-local temporary error handler, and its user data.
Definition cpl_error.h:417
~CPLErrorHandlerPusher()
Destructor that restores the initial error handler.
Definition cpl_error.h:423
Class that saves the error state on construction, and restores it on destruction.
Definition cpl_error.h:433
Class that turns errors into warning on construction, and restores the previous state on destruction.
Definition cpl_error.h:456
void CPLQuietWarningsErrorHandler(CPLErr, CPLErrorNum, const char *)
Error handler that ignores CE_Warning messages.
Definition cpl_error.cpp:1126
#define CPLE_IllegalArg
Illegal argument.
Definition cpl_error.h:116
void CPLErrorSetState(CPLErr eErrClass, CPLErrorNum err_no, const char *pszMsg)
Restore an error state, without emitting an error.
Definition cpl_error.cpp:890
GUInt32 CPLGetErrorCounter(void)
Get the error counter.
Definition cpl_error.cpp:981
#define CPLE_AssertionFailed
Assertion failed.
Definition cpl_error.h:120
void CPLPushErrorHandlerEx(CPLErrorHandler, void *)
Push a new CPLError handler with user data on the error context.
Definition cpl_error.cpp:1364
#define CPLE_None
No error.
Definition cpl_error.h:106
#define CPLE_ObjectNotFound
VSIE_ObjectNotFound.
Definition cpl_error.h:136
void CPLErrorReset(void)
Erase any traces of previous errors.
Definition cpl_error.cpp:815
void CPLLoggingErrorHandler(CPLErr, CPLErrorNum, const char *)
Error handler that logs into the file defined by the CPL_LOG configuration option,...
Definition cpl_error.cpp:1142
#define CPLE_NotSupported
Not supported.
Definition cpl_error.h:118
#define CPLAssert(expr)
Assert on an expression.
Definition cpl_error.h:353
CPLErr
Error category / error level.
Definition cpl_error.h:45
@ CE_Warning
Non-nominal situation that is worth bringing to the attention of the user, but that does not prevent ...
Definition cpl_error.h:55
@ CE_Debug
Debug message.
Definition cpl_error.h:50
@ CE_None
No error.
Definition cpl_error.h:47
@ CE_Fatal
Fatal unrecoverable error.
Definition cpl_error.h:65
@ CE_Failure
Error that prevents the current operation to succeed.
Definition cpl_error.h:60
#define CPLE_FileIO
File I/O error.
Definition cpl_error.h:112
CPLErrorNum CPLGetLastErrorNo(void)
Fetch the last error number.
Definition cpl_error.cpp:911
void CPLDebugProgress(const char *, const char *,...)
Display a debugging message indicating a progression.
Definition cpl_error.cpp:785
#define CPLE_AppDefined
Application defined error.
Definition cpl_error.h:108
#define CPLE_OpenFailed
Open failed.
Definition cpl_error.h:114
const char * CPLGetLastErrorMsg(void)
Get the last error message.
Definition cpl_error.cpp:959
CPLErrorHandler CPLGetErrorHandler(void **ppUserData)
Fetch the current error handler for the current error context.
Definition cpl_error.cpp:175
CPLErrorHandler CPLSetErrorHandler(CPLErrorHandler)
Install custom error handler.
Definition cpl_error.cpp:1320
#define CPLE_AccessDenied
VSIE_AccessDenied.
Definition cpl_error.h:138
#define CPLE_ObjectNull
NULL object.
Definition cpl_error.h:126
void CPLDefaultErrorHandler(CPLErr, CPLErrorNum, const char *)
Default error handler.
Definition cpl_error.cpp:1015
CPLErr CPLGetLastErrorType(void)
Fetch the last error type.
Definition cpl_error.cpp:935
int CPLErrorNum
Error number.
Definition cpl_error.h:103
void * CPLGetErrorHandlerUserData(void)
Fetch the user data for the error context.
Definition cpl_error.cpp:147
void(* CPLErrorHandler)(CPLErr, CPLErrorNum, const char *)
Callback for a custom error handler.
Definition cpl_error.h:247
void CPLTurnFailureIntoWarning(int bOn)
Whether failures should be turned into warnings.
Definition cpl_error.cpp:1215
void CPLCallPreviousHandler(CPLErr eErrClass, CPLErrorNum err_no, const char *pszMsg)
Call the previously installed error handler in the error handler stack.
Definition cpl_error.cpp:1431
#define CPLE_InvalidCredentials
VSIE_InvalidCredentials.
Definition cpl_error.h:140
void CPLEmergencyError(const char *)
Fatal error when things are bad.
Definition cpl_error.cpp:496
#define CPLE_SignatureDoesNotMatch
VSIE_SignatureDoesNotMatch.
Definition cpl_error.h:142
void _CPLAssert(const char *, const char *, int)
Report failure of a logical assertion.
Definition cpl_error.cpp:1519
#define CPLE_HttpResponse
HTTP response.
Definition cpl_error.h:132
void CPLPopErrorHandler(void)
Pop error handler off stack.
Definition cpl_error.cpp:1398
#define CPLE_BucketNotFound
VSIE_BucketNotFound.
Definition cpl_error.h:134
void CPLDebug(const char *, const char *,...)
Display a debugging message.
Definition cpl_error.cpp:740
void CPLPushErrorHandler(CPLErrorHandler)
Push a new CPLError handler.
Definition cpl_error.cpp:1341
#define CPLE_NoWriteAccess
No write access.
Definition cpl_error.h:122
#define CPLE_ObjectStorageGenericError
VSIE_ObjectStorageGenericError.
Definition cpl_error.h:144
#define CPLE_UserInterrupt
User interrupted.
Definition cpl_error.h:124
void CPLErrorV(CPLErr, CPLErrorNum, const char *, va_list)
Same as CPLError() but with a va_list.
Definition cpl_error.cpp:332
void CPLQuietErrorHandler(CPLErr, CPLErrorNum, const char *)
Error handler that does not do anything, except for debug messages.
Definition cpl_error.cpp:1113
#define CPLE_OutOfMemory
Out of memory error.
Definition cpl_error.h:110
CPLErrorHandler CPLSetErrorHandlerEx(CPLErrorHandler, void *)
Install custom error handle with user's data.
Definition cpl_error.cpp:1247
void CPLSetCurrentErrorHandlerCatchDebug(int bCatchDebug)
Set if the current error handler should intercept debug messages, or if they should be processed by t...
Definition cpl_error.cpp:1485
void CPLError(CPLErr eErrClass, CPLErrorNum err_no, const char *fmt,...)
Report an error.
Definition cpl_error.cpp:316
Core portability definitions for CPL.
#define CPL_NO_RETURN
Qualifier for a function that does not return at all (terminates the process)
Definition cpl_port.h:1054
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:279
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:275
#define CPL_FORMAT_STRING(arg)
Macro into which to wrap the format argument of a printf-like function.
Definition cpl_port.h:1025
#define CPL_RETURNS_NONNULL
Qualifier for a function that does not return NULL.
Definition cpl_port.h:1073
unsigned int GUInt32
Unsigned int32 type.
Definition cpl_port.h:157
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition cpl_port.h:1009
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition cpl_port.h:1035