SDTS_AL
cpl_error.h
Go to the documentation of this file.
1/**********************************************************************
2 * $Id$
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
49CPL_C_START
50
52typedef 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 */
70typedef enum
71{
90
91#else
92
94typedef int CPLErrorNum;
95
97#define CPLE_None 0
99#define CPLE_AppDefined 1
101#define CPLE_OutOfMemory 2
103#define CPLE_FileIO 3
105#define CPLE_OpenFailed 4
107#define CPLE_IllegalArg 5
109#define CPLE_NotSupported 6
111#define CPLE_AssertionFailed 7
113#define CPLE_NoWriteAccess 8
115#define CPLE_UserInterrupt 9
117#define CPLE_ObjectNull 10
118
119/*
120 * Filesystem-specific errors
121 */
123#define CPLE_HttpResponse 11
125#define CPLE_AWSBucketNotFound 12
127#define CPLE_AWSObjectNotFound 13
129#define CPLE_AWSAccessDenied 14
131#define CPLE_AWSInvalidCredentials 15
133#define CPLE_AWSSignatureDoesNotMatch 16
134
135/* 100 - 299 reserved for GDAL */
136
137#endif
138
139void CPL_DLL CPLError(CPLErr eErrClass, CPLErrorNum err_no, CPL_FORMAT_STRING(const char *fmt), ...) CPL_PRINT_FUNC_FORMAT (3, 4);
140void CPL_DLL CPLErrorV(CPLErr, CPLErrorNum, const char *, va_list );
141void CPL_DLL CPLEmergencyError( const char * ) CPL_NO_RETURN;
142void CPL_DLL CPL_STDCALL CPLErrorReset( void );
143CPLErrorNum CPL_DLL CPL_STDCALL CPLGetLastErrorNo( void );
144CPLErr CPL_DLL CPL_STDCALL CPLGetLastErrorType( void );
145const char CPL_DLL * CPL_STDCALL CPLGetLastErrorMsg( void );
146GUInt32 CPL_DLL CPL_STDCALL CPLGetErrorCounter( void );
147void CPL_DLL * CPL_STDCALL CPLGetErrorHandlerUserData(void);
148void CPL_DLL CPLErrorSetState( CPLErr eErrClass, CPLErrorNum err_no, const char* pszMsg );
150void CPL_DLL CPLCleanupErrorMutex( void );
154typedef void (CPL_STDCALL *CPLErrorHandler)(CPLErr, CPLErrorNum, const char*);
155
156void CPL_DLL CPL_STDCALL CPLLoggingErrorHandler( CPLErr, CPLErrorNum, const char * );
157void CPL_DLL CPL_STDCALL CPLDefaultErrorHandler( CPLErr, CPLErrorNum, const char * );
158void CPL_DLL CPL_STDCALL CPLQuietErrorHandler( CPLErr, CPLErrorNum, const char * );
159void CPLTurnFailureIntoWarning( int bOn );
160
162CPLErrorHandler CPL_DLL CPL_STDCALL CPLSetErrorHandlerEx( CPLErrorHandler, void* );
163void CPL_DLL CPL_STDCALL CPLPushErrorHandler( CPLErrorHandler );
164void CPL_DLL CPL_STDCALL CPLPushErrorHandlerEx( CPLErrorHandler, void* );
165void CPL_DLL CPL_STDCALL CPLSetCurrentErrorHandlerCatchDebug( int bCatchDebug );
166void CPL_DLL CPL_STDCALL CPLPopErrorHandler(void);
167
168#ifdef WITHOUT_CPLDEBUG
169#define CPLDebug(...) /* Eat all CPLDebug calls. */
170#else
171void CPL_DLL CPL_STDCALL CPLDebug(const char *, CPL_FORMAT_STRING(const char *), ...)
173#endif
174
175void CPL_DLL CPL_STDCALL _CPLAssert( const char *, const char *, int ) CPL_NO_RETURN;
176
177#ifdef DEBUG
179# define CPLAssert(expr) ((expr) ? (void)(0) : _CPLAssert(#expr,__FILE__,__LINE__))
180#else
182# define CPLAssert(expr)
183#endif
184
185CPL_C_END
186
188/*
189 * Helper macros used for input parameters validation.
190 */
191#ifdef DEBUG
192# define VALIDATE_POINTER_ERR CE_Fatal
193#else
194# define VALIDATE_POINTER_ERR CE_Failure
195#endif
196
197
198#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && !defined(DOXYGEN_SKIP)
199
200extern "C++"
201{
202
203#include <string>
204
205class CPLErrorHandlerPusher
206{
207 public:
208 explicit CPLErrorHandlerPusher(CPLErrorHandler hHandler)
209 {
210 CPLPushErrorHandler(hHandler);
211 }
212
213 CPLErrorHandlerPusher(CPLErrorHandler hHandler, void* user_data)
214 {
215 CPLPushErrorHandlerEx(hHandler, user_data);
216 }
217
218 ~CPLErrorHandlerPusher()
219 {
221 }
222};
223
224class CPLErrorStateBackuper
225{
226 CPLErrorNum m_nLastErrorNum;
227 CPLErr m_nLastErrorType;
228 std::string m_osLastErrorMsg;
229
230 public:
231 CPLErrorStateBackuper() :
232 m_nLastErrorNum(CPLGetLastErrorNo()),
233 m_nLastErrorType(CPLGetLastErrorType()),
234 m_osLastErrorMsg(CPLGetLastErrorMsg())
235 {}
236
237 ~CPLErrorStateBackuper()
238 {
239 CPLErrorSetState(m_nLastErrorType, m_nLastErrorNum,
240 m_osLastErrorMsg.c_str());
241 }
242};
243
244}
245
246#endif
247
251#define VALIDATE_POINTER0(ptr, func) \
252 do { if( CPL_NULLPTR == ptr ) \
253 { \
254 CPLErr const ret = VALIDATE_POINTER_ERR; \
255 CPLError( ret, CPLE_ObjectNull, \
256 "Pointer \'%s\' is NULL in \'%s\'.\n", #ptr, (func)); \
257 return; }} while(0)
258
260#define VALIDATE_POINTER1(ptr, func, rc) \
261 do { if( CPL_NULLPTR == ptr ) \
262 { \
263 CPLErr const ret = VALIDATE_POINTER_ERR; \
264 CPLError( ret, CPLE_ObjectNull, \
265 "Pointer \'%s\' is NULL in \'%s\'.\n", #ptr, (func)); \
266 return (rc); }} while(0)
267
268#endif /* CPL_ERROR_H_INCLUDED */
void CPL_DLL *CPL_STDCALL CPLGetErrorHandlerUserData(void)
Definition: cpl_error.cpp:186
#define CPLE_IllegalArg
Definition: cpl_error.h:107
#define CPLE_AWSObjectNotFound
Definition: cpl_error.h:127
#define CPLE_AssertionFailed
Definition: cpl_error.h:111
CPLErrorHandler CPL_DLL CPL_STDCALL CPLSetErrorHandler(CPLErrorHandler)
Definition: cpl_error.cpp:1145
void CPL_DLL CPL_STDCALL CPLSetCurrentErrorHandlerCatchDebug(int bCatchDebug)
Definition: cpl_error.cpp:1262
#define CPLE_AWSSignatureDoesNotMatch
Definition: cpl_error.h:133
CPLErr CPL_DLL CPL_STDCALL CPLGetLastErrorType(void)
Definition: cpl_error.cpp:823
void CPL_DLL CPL_STDCALL CPLErrorReset(void)
Definition: cpl_error.cpp:710
void CPL_DLL CPL_STDCALL CPLPopErrorHandler(void)
Definition: cpl_error.cpp:1223
#define CPLE_None
Definition: cpl_error.h:97
void CPL_DLL CPLEmergencyError(const char *) CPL_NO_RETURN
Definition: cpl_error.cpp:423
void CPL_DLL CPLErrorSetState(CPLErr eErrClass, CPLErrorNum err_no, const char *pszMsg)
Definition: cpl_error.cpp:745
void CPL_DLL CPL_STDCALL CPLPushErrorHandler(CPLErrorHandler)
Definition: cpl_error.cpp:1166
#define CPLE_NotSupported
Definition: cpl_error.h:109
#define CPLE_AWSInvalidCredentials
Definition: cpl_error.h:131
CPLErr
Definition: cpl_error.h:53
#define CPLE_FileIO
Definition: cpl_error.h:103
void CPL_DLL void CPL_DLL CPLErrorV(CPLErr, CPLErrorNum, const char *, va_list)
Definition: cpl_error.cpp:248
CPLErrorHandler CPL_DLL CPL_STDCALL CPLSetErrorHandlerEx(CPLErrorHandler, void *)
Definition: cpl_error.cpp:1071
void CPL_DLL CPL_STDCALL CPLPushErrorHandlerEx(CPLErrorHandler, void *)
Definition: cpl_error.cpp:1189
void CPL_DLL CPL_STDCALL CPLDefaultErrorHandler(CPLErr, CPLErrorNum, const char *)
Definition: cpl_error.cpp:884
#define CPLE_AppDefined
Definition: cpl_error.h:99
#define CPLE_OpenFailed
Definition: cpl_error.h:105
const char CPL_DLL *CPL_STDCALL CPLGetLastErrorMsg(void)
Definition: cpl_error.cpp:847
#define CPLE_AWSAccessDenied
Definition: cpl_error.h:129
#define CPLE_ObjectNull
Definition: cpl_error.h:117
int CPLErrorNum
Definition: cpl_error.h:94
void CPLTurnFailureIntoWarning(int bOn)
Definition: cpl_error.cpp:1039
void CPL_DLL CPL_STDCALL CPLLoggingErrorHandler(CPLErr, CPLErrorNum, const char *)
Definition: cpl_error.cpp:963
#define CPLE_HttpResponse
Definition: cpl_error.h:123
#define CPLE_AWSBucketNotFound
Definition: cpl_error.h:125
void CPL_DLL CPL_STDCALL void CPL_DLL CPL_STDCALL _CPLAssert(const char *, const char *, int) CPL_NO_RETURN
Definition: cpl_error.cpp:1296
CPLErrorNum CPL_DLL CPL_STDCALL CPLGetLastErrorNo(void)
Definition: cpl_error.cpp:799
#define CPLE_NoWriteAccess
Definition: cpl_error.h:113
void(CPL_STDCALL * CPLErrorHandler)(CPLErr, CPLErrorNum, const char *)
Definition: cpl_error.h:154
#define CPLE_UserInterrupt
Definition: cpl_error.h:115
void CPL_DLL CPL_STDCALL CPLQuietErrorHandler(CPLErr, CPLErrorNum, const char *)
Definition: cpl_error.cpp:948
#define CPLE_OutOfMemory
Definition: cpl_error.h:101
GUInt32 CPL_DLL CPL_STDCALL CPLGetErrorCounter(void)
Definition: cpl_error.cpp:870
#define CPL_NO_RETURN
Definition: cpl_port.h:946
#define CPL_FORMAT_STRING(arg)
Definition: cpl_port.h:919
unsigned int GUInt32
Definition: cpl_port.h:205
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Definition: cpl_port.h:904