OGR
cpl_error.h
Go to the documentation of this file.
1 /**********************************************************************
2  * $Id: cpl_error.h e3511844a11959bd81f5956a1e7e2de96900e7ac 2019-04-25 11:53:15 +0200 Even Rouault $
3  *
4  * Name: cpl_error.h
5  * Project: CPL - Common Portability Library
6  * Purpose: CPL Error handling
7  * Author: Daniel Morissette, danmo@videotron.ca
8  *
9  **********************************************************************
10  * Copyright (c) 1998, Daniel Morissette
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included
20  * in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28  * DEALINGS IN THE SOFTWARE.
29  ****************************************************************************/
30 
31 #ifndef CPL_ERROR_H_INCLUDED
32 #define CPL_ERROR_H_INCLUDED
33 
34 #include "cpl_port.h"
35 
36 #include <stdarg.h>
37 #include <stddef.h>
38 
39 /*=====================================================================
40  Error handling functions (cpl_error.c)
41  =====================================================================*/
42 
50 
52 typedef enum
53 {
54  CE_None = 0,
55  CE_Debug = 1,
56  CE_Warning = 2,
57  CE_Failure = 3,
58  CE_Fatal = 4
59 } CPLErr;
60 
61 /* ==================================================================== */
62 /* Well known error codes. */
63 /* ==================================================================== */
64 
65 #ifdef STRICT_CPLERRORNUM_TYPE
66 
67 /* This is not appropriate for the general case, as there are parts */
68 /* of GDAL which use custom error codes, but this can help diagnose confusions */
69 /* between CPLErr and CPLErrorNum */
70 typedef enum
71 {
72  CPLE_None,
89 } CPLErrorNum;
90 
91 #else
92 
94 typedef int CPLErrorNum;
95 
97 #define CPLE_None 0
98 
99 #define CPLE_AppDefined 1
100 
101 #define CPLE_OutOfMemory 2
102 
103 #define CPLE_FileIO 3
104 
105 #define CPLE_OpenFailed 4
106 
107 #define CPLE_IllegalArg 5
108 
109 #define CPLE_NotSupported 6
110 
111 #define CPLE_AssertionFailed 7
112 
113 #define CPLE_NoWriteAccess 8
114 
115 #define CPLE_UserInterrupt 9
116 
117 #define CPLE_ObjectNull 10
118 
119 /*
120  * Filesystem-specific errors
121  */
123 #define CPLE_HttpResponse 11
124 
125 #define CPLE_AWSBucketNotFound 12
126 
127 #define CPLE_AWSObjectNotFound 13
128 
129 #define CPLE_AWSAccessDenied 14
130 
131 #define CPLE_AWSInvalidCredentials 15
132 
133 #define CPLE_AWSSignatureDoesNotMatch 16
134 
135 #define CPLE_AWSError 17
136 
137 /* 100 - 299 reserved for GDAL */
138 
139 #endif
140 
141 void CPL_DLL CPLError(CPLErr eErrClass, CPLErrorNum err_no, CPL_FORMAT_STRING(const char *fmt), ...) CPL_PRINT_FUNC_FORMAT (3, 4);
142 void CPL_DLL CPLErrorV(CPLErr, CPLErrorNum, const char *, va_list );
143 void CPL_DLL CPLEmergencyError( const char * ) CPL_NO_RETURN;
144 void CPL_DLL CPL_STDCALL CPLErrorReset( void );
145 CPLErrorNum CPL_DLL CPL_STDCALL CPLGetLastErrorNo( void );
146 CPLErr CPL_DLL CPL_STDCALL CPLGetLastErrorType( void );
147 const char CPL_DLL * CPL_STDCALL CPLGetLastErrorMsg( void );
148 GUInt32 CPL_DLL CPL_STDCALL CPLGetErrorCounter( void );
149 void CPL_DLL * CPL_STDCALL CPLGetErrorHandlerUserData(void);
150 void CPL_DLL CPLErrorSetState( CPLErr eErrClass, CPLErrorNum err_no, const char* pszMsg );
152 void CPL_DLL CPLCleanupErrorMutex( void );
156 typedef void (CPL_STDCALL *CPLErrorHandler)(CPLErr, CPLErrorNum, const char*);
157 
158 void CPL_DLL CPL_STDCALL CPLLoggingErrorHandler( CPLErr, CPLErrorNum, const char * );
159 void CPL_DLL CPL_STDCALL CPLDefaultErrorHandler( CPLErr, CPLErrorNum, const char * );
160 void CPL_DLL CPL_STDCALL CPLQuietErrorHandler( CPLErr, CPLErrorNum, const char * );
161 void CPLTurnFailureIntoWarning( int bOn );
162 
163 CPLErrorHandler CPL_DLL CPL_STDCALL CPLSetErrorHandler( CPLErrorHandler );
164 CPLErrorHandler CPL_DLL CPL_STDCALL CPLSetErrorHandlerEx( CPLErrorHandler, void* );
165 void CPL_DLL CPL_STDCALL CPLPushErrorHandler( CPLErrorHandler );
166 void CPL_DLL CPL_STDCALL CPLPushErrorHandlerEx( CPLErrorHandler, void* );
167 void CPL_DLL CPL_STDCALL CPLSetCurrentErrorHandlerCatchDebug( int bCatchDebug );
168 void CPL_DLL CPL_STDCALL CPLPopErrorHandler(void);
169 
170 #ifdef WITHOUT_CPLDEBUG
171 #define CPLDebug(...) /* Eat all CPLDebug calls. */
172 #else
173 void CPL_DLL CPL_STDCALL CPLDebug(const char *, CPL_FORMAT_STRING(const char *), ...)
174  CPL_PRINT_FUNC_FORMAT(2, 3);
175 #endif
176 
177 void CPL_DLL CPL_STDCALL _CPLAssert( const char *, const char *, int ) CPL_NO_RETURN;
178 
179 #ifdef DEBUG
180 
181 # define CPLAssert(expr) ((expr) ? (void)(0) : _CPLAssert(#expr,__FILE__,__LINE__))
182 
183 # define CPLAssertAlwaysEval(expr) CPLAssert(expr)
184 #else
185 
186 # define CPLAssert(expr)
187 #ifdef __cplusplus
188 
189 # define CPLAssertAlwaysEval(expr) CPL_IGNORE_RET_VAL(expr)
190 #else
191 
192 # define CPLAssertAlwaysEval(expr) (void)(expr)
193 #endif
194 #endif
195 
196 CPL_C_END
197 
199 /*
200  * Helper macros used for input parameters validation.
201  */
202 #ifdef DEBUG
203 # define VALIDATE_POINTER_ERR CE_Fatal
204 #else
205 # define VALIDATE_POINTER_ERR CE_Failure
206 #endif
207 
208 
209 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && !defined(DOXYGEN_SKIP)
210 
211 extern "C++"
212 {
213 
214 #include <string>
215 
216 class CPLErrorHandlerPusher
217 {
218  public:
219  explicit CPLErrorHandlerPusher(CPLErrorHandler hHandler)
220  {
221  CPLPushErrorHandler(hHandler);
222  }
223 
224  CPLErrorHandlerPusher(CPLErrorHandler hHandler, void* user_data)
225  {
226  CPLPushErrorHandlerEx(hHandler, user_data);
227  }
228 
229  ~CPLErrorHandlerPusher()
230  {
232  }
233 };
234 
235 class CPLErrorStateBackuper
236 {
237  CPLErrorNum m_nLastErrorNum;
238  CPLErr m_nLastErrorType;
239  std::string m_osLastErrorMsg;
240 
241  public:
242  CPLErrorStateBackuper() :
243  m_nLastErrorNum(CPLGetLastErrorNo()),
244  m_nLastErrorType(CPLGetLastErrorType()),
245  m_osLastErrorMsg(CPLGetLastErrorMsg())
246  {}
247 
248  ~CPLErrorStateBackuper()
249  {
250  CPLErrorSetState(m_nLastErrorType, m_nLastErrorNum,
251  m_osLastErrorMsg.c_str());
252  }
253 };
254 
255 }
256 
257 #ifdef GDAL_COMPILATION
258 // internal only
259 bool CPLIsDefaultErrorHandlerAndCatchDebug();
260 #endif
261 
262 #endif
263 
267 #define VALIDATE_POINTER0(ptr, func) \
268  do { if( CPL_NULLPTR == ptr ) \
269  { \
270  CPLErr const ret = VALIDATE_POINTER_ERR; \
271  CPLError( ret, CPLE_ObjectNull, \
272  "Pointer \'%s\' is NULL in \'%s\'.\n", #ptr, (func)); \
273  return; }} while(0)
274 
276 #define VALIDATE_POINTER1(ptr, func, rc) \
277  do { if( CPL_NULLPTR == ptr ) \
278  { \
279  CPLErr const ret = VALIDATE_POINTER_ERR; \
280  CPLError( ret, CPLE_ObjectNull, \
281  "Pointer \'%s\' is NULL in \'%s\'.\n", #ptr, (func)); \
282  return (rc); }} while(0)
283 
284 #endif /* CPL_ERROR_H_INCLUDED */
CPLGetErrorCounter
GUInt32 CPLGetErrorCounter(void)
Definition: cpl_error.cpp:889
CPL_PRINT_FUNC_FORMAT
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Definition: cpl_port.h:914
_CPLAssert
void _CPLAssert(const char *, const char *, int)
Definition: cpl_error.cpp:1315
CPLLoggingErrorHandler
void CPLLoggingErrorHandler(CPLErr, CPLErrorNum, const char *)
Definition: cpl_error.cpp:982
CPLGetLastErrorMsg
const char * CPLGetLastErrorMsg(void)
Definition: cpl_error.cpp:866
CPLErrorHandler
void(* CPLErrorHandler)(CPLErr, CPLErrorNum, const char *)
Definition: cpl_error.h:156
CPLE_UserInterrupt
#define CPLE_UserInterrupt
Definition: cpl_error.h:115
cpl_error.h
CPLPopErrorHandler
void CPLPopErrorHandler(void)
Definition: cpl_error.cpp:1242
cpl_vsi.h
CPLsnprintf
int CPLsnprintf(char *str, size_t size, const char *fmt,...)
Definition: cpl_string.cpp:1337
CPLSetErrorHandlerEx
CPLErrorHandler CPLSetErrorHandlerEx(CPLErrorHandler, void *)
Definition: cpl_error.cpp:1090
CPLE_NoWriteAccess
#define CPLE_NoWriteAccess
Definition: cpl_error.h:113
CPLRealloc
void * CPLRealloc(void *, size_t)
Definition: cpl_conv.cpp:225
CPL_NO_RETURN
#define CPL_NO_RETURN
Definition: cpl_port.h:956
EQUAL
#define EQUAL(a, b)
Definition: cpl_port.h:569
CPLDefaultErrorHandler
void CPLDefaultErrorHandler(CPLErr, CPLErrorNum, const char *)
Definition: cpl_error.cpp:903
CPLPushErrorHandler
void CPLPushErrorHandler(CPLErrorHandler)
Definition: cpl_error.cpp:1185
CPLE_AWSBucketNotFound
#define CPLE_AWSBucketNotFound
Definition: cpl_error.h:125
CPL_C_START
#define CPL_C_START
Definition: cpl_port.h:337
CPLE_OutOfMemory
#define CPLE_OutOfMemory
Definition: cpl_error.h:101
CPLGetLastErrorNo
CPLErrorNum CPLGetLastErrorNo(void)
Definition: cpl_error.cpp:818
CPLE_ObjectNull
#define CPLE_ObjectNull
Definition: cpl_error.h:117
CPLErrorNum
int CPLErrorNum
Definition: cpl_error.h:94
CPLE_OpenFailed
#define CPLE_OpenFailed
Definition: cpl_error.h:105
CPL_C_END
#define CPL_C_END
Definition: cpl_port.h:339
CPLE_HttpResponse
#define CPLE_HttpResponse
Definition: cpl_error.h:123
CPLDebug
void CPLDebug(const char *, const char *,...)
Definition: cpl_error.cpp:602
STARTS_WITH
#define STARTS_WITH(a, b)
Definition: cpl_port.h:578
CPLMalloc
void * CPLMalloc(size_t)
Definition: cpl_conv.cpp:168
cpl_conv.h
cpl_string.h
CPLE_AWSSignatureDoesNotMatch
#define CPLE_AWSSignatureDoesNotMatch
Definition: cpl_error.h:133
CPLErrorReset
void CPLErrorReset(void)
Definition: cpl_error.cpp:729
CPLvsnprintf
int CPLvsnprintf(char *str, size_t size, const char *fmt, va_list args)
Definition: cpl_string.cpp:1140
CPLE_AWSObjectNotFound
#define CPLE_AWSObjectNotFound
Definition: cpl_error.h:127
CPLError
void CPLError(CPLErr eErrClass, CPLErrorNum err_no, const char *fmt,...)
Definition: cpl_error.cpp:308
CPLEmergencyError
void CPLEmergencyError(const char *)
Definition: cpl_error.cpp:489
CPLE_AssertionFailed
#define CPLE_AssertionFailed
Definition: cpl_error.h:111
VSIFree
void VSIFree(void *)
Definition: cpl_vsisimple.cpp:827
CPLSetErrorHandler
CPLErrorHandler CPLSetErrorHandler(CPLErrorHandler)
Definition: cpl_error.cpp:1164
CPLE_NotSupported
#define CPLE_NotSupported
Definition: cpl_error.h:109
CPLPushErrorHandlerEx
void CPLPushErrorHandlerEx(CPLErrorHandler, void *)
Definition: cpl_error.cpp:1208
CPLSetConfigOption
void CPLSetConfigOption(const char *, const char *)
Definition: cpl_conv.cpp:1832
VSICalloc
void * VSICalloc(size_t, size_t)
Definition: cpl_vsisimple.cpp:444
CPLErrorContext
Definition: cpl_error.cpp:76
VSIMalloc
void * VSIMalloc(size_t)
Definition: cpl_vsisimple.cpp:558
CPL_FORMAT_STRING
#define CPL_FORMAT_STRING(arg)
Definition: cpl_port.h:929
cpl_port.h
EQUALN
#define EQUALN(a, b, n)
Definition: cpl_port.h:567
CPLErrorSetState
void CPLErrorSetState(CPLErr eErrClass, CPLErrorNum err_no, const char *pszMsg)
Definition: cpl_error.cpp:764
CPLE_None
#define CPLE_None
Definition: cpl_error.h:97
CPLErr
CPLErr
Definition: cpl_error.h:53
CPLE_AWSAccessDenied
#define CPLE_AWSAccessDenied
Definition: cpl_error.h:129
errHandler
Definition: cpl_error.cpp:69
CPLStrdup
char * CPLStrdup(const char *)
Definition: cpl_conv.cpp:293
CPLGetLastErrorType
CPLErr CPLGetLastErrorType(void)
Definition: cpl_error.cpp:842
CPLE_AWSInvalidCredentials
#define CPLE_AWSInvalidCredentials
Definition: cpl_error.h:131
CPLE_IllegalArg
#define CPLE_IllegalArg
Definition: cpl_error.h:107
CPLGetErrorHandlerUserData
void * CPLGetErrorHandlerUserData(void)
Definition: cpl_error.cpp:186
CPLSetCurrentErrorHandlerCatchDebug
void CPLSetCurrentErrorHandlerCatchDebug(int bCatchDebug)
Definition: cpl_error.cpp:1281
CPLQuietErrorHandler
void CPLQuietErrorHandler(CPLErr, CPLErrorNum, const char *)
Definition: cpl_error.cpp:967
CPLErrorV
void CPLErrorV(CPLErr, CPLErrorNum, const char *, va_list)
Definition: cpl_error.cpp:324
CPLE_FileIO
#define CPLE_FileIO
Definition: cpl_error.h:103
CPLFree
#define CPLFree
Definition: cpl_conv.h:81
CPLTurnFailureIntoWarning
void CPLTurnFailureIntoWarning(int bOn)
Definition: cpl_error.cpp:1058
CPLGetConfigOption
const char * CPLGetConfigOption(const char *, const char *)
Definition: cpl_conv.cpp:1692
CPLE_AppDefined
#define CPLE_AppDefined
Definition: cpl_error.h:99
GUInt32
unsigned int GUInt32
Definition: cpl_port.h:207

Generated for GDAL by doxygen 1.8.20.