OGR
cpl_error.h
Go to the documentation of this file.
1 /**********************************************************************
2  * $Id: cpl_error.h 33842 2016-04-01 08:37:32Z 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 /*=====================================================================
37  Error handling functions (cpl_error.c)
38  =====================================================================*/
39 
46 CPL_C_START
47 
48 typedef enum
49 {
50  CE_None = 0,
51  CE_Debug = 1,
52  CE_Warning = 2,
53  CE_Failure = 3,
54  CE_Fatal = 4
55 } CPLErr;
56 
57 /* ==================================================================== */
58 /* Well known error codes. */
59 /* ==================================================================== */
60 
61 #ifdef STRICT_CPLERRORNUM_TYPE
62 
63 /* This is not appropriate for the general case, as there are parts */
64 /* of GDAL which use custom error codes, but this can help diagnose confusions */
65 /* between CPLErr and CPLErrorNum */
66 typedef enum
67 {
68  CPLE_None,
69  CPLE_AppDefined,
70  CPLE_OutOfMemory,
71  CPLE_FileIO,
72  CPLE_OpenFailed,
73  CPLE_IllegalArg,
74  CPLE_NotSupported,
75  CPLE_AssertionFailed,
76  CPLE_NoWriteAccess,
77  CPLE_UserInterrupt,
78  CPLE_ObjectNull,
79  CPLE_HttpResponse,
80  CPLE_HttpResponse,
81  CPLE_AWSBucketNotFound,
82  CPLE_AWSObjectNotFound,
83  CPLE_AWSAccessDenied,
84  CPLE_AWSInvalidCredentials,
85  CPLE_AWSSignatureDoesNotMatch,
86 } CPLErrorNum;
87 
88 #else
89 
90 typedef int CPLErrorNum;
91 
92 #define CPLE_None 0
93 #define CPLE_AppDefined 1
94 #define CPLE_OutOfMemory 2
95 #define CPLE_FileIO 3
96 #define CPLE_OpenFailed 4
97 #define CPLE_IllegalArg 5
98 #define CPLE_NotSupported 6
99 #define CPLE_AssertionFailed 7
100 #define CPLE_NoWriteAccess 8
101 #define CPLE_UserInterrupt 9
102 #define CPLE_ObjectNull 10
103 
104 /*
105  * Filesystem-specific errors
106  */
107 #define CPLE_HttpResponse 11
108 #define CPLE_AWSBucketNotFound 12
109 #define CPLE_AWSObjectNotFound 13
110 #define CPLE_AWSAccessDenied 14
111 #define CPLE_AWSInvalidCredentials 15
112 #define CPLE_AWSSignatureDoesNotMatch 16
113 
114 /* 100 - 299 reserved for GDAL */
115 
116 #endif
117 
118 void CPL_DLL CPLError(CPLErr eErrClass, CPLErrorNum err_no, const char *fmt, ...) CPL_PRINT_FUNC_FORMAT (3, 4);
119 void CPL_DLL CPLErrorV(CPLErr, CPLErrorNum, const char *, va_list );
120 void CPL_DLL CPLEmergencyError( const char * ) CPL_NO_RETURN;
121 void CPL_DLL CPL_STDCALL CPLErrorReset( void );
122 CPLErrorNum CPL_DLL CPL_STDCALL CPLGetLastErrorNo( void );
123 CPLErr CPL_DLL CPL_STDCALL CPLGetLastErrorType( void );
124 const char CPL_DLL * CPL_STDCALL CPLGetLastErrorMsg( void );
125 void CPL_DLL * CPL_STDCALL CPLGetErrorHandlerUserData(void);
126 void CPL_DLL CPLErrorSetState( CPLErr eErrClass, CPLErrorNum err_no, const char* pszMsg );
127 void CPL_DLL CPLCleanupErrorMutex( void );
128 
129 typedef void (CPL_STDCALL *CPLErrorHandler)(CPLErr, CPLErrorNum, const char*);
130 
131 void CPL_DLL CPL_STDCALL CPLLoggingErrorHandler( CPLErr, CPLErrorNum, const char * );
132 void CPL_DLL CPL_STDCALL CPLDefaultErrorHandler( CPLErr, CPLErrorNum, const char * );
133 void CPL_DLL CPL_STDCALL CPLQuietErrorHandler( CPLErr, CPLErrorNum, const char * );
134 void CPLTurnFailureIntoWarning(int bOn );
135 
136 CPLErrorHandler CPL_DLL CPL_STDCALL CPLSetErrorHandler(CPLErrorHandler);
137 CPLErrorHandler CPL_DLL CPL_STDCALL CPLSetErrorHandlerEx(CPLErrorHandler, void*);
138 void CPL_DLL CPL_STDCALL CPLPushErrorHandler( CPLErrorHandler );
139 void CPL_DLL CPL_STDCALL CPLPushErrorHandlerEx( CPLErrorHandler, void* );
140 void CPL_DLL CPL_STDCALL CPLSetCurrentErrorHandlerCatchDebug( int bCatchDebug );
141 void CPL_DLL CPL_STDCALL CPLPopErrorHandler(void);
142 
143 void CPL_DLL CPL_STDCALL CPLDebug( const char *, const char *, ... ) CPL_PRINT_FUNC_FORMAT (2, 3);
144 void CPL_DLL CPL_STDCALL _CPLAssert( const char *, const char *, int ) CPL_NO_RETURN;
145 
146 #ifdef DEBUG
147 # define CPLAssert(expr) ((expr) ? (void)(0) : _CPLAssert(#expr,__FILE__,__LINE__))
148 #else
149 # define CPLAssert(expr)
150 #endif
151 
152 CPL_C_END
153 
154 /*
155  * Helper macros used for input parameters validation.
156  */
157 #ifdef DEBUG
158 # define VALIDATE_POINTER_ERR CE_Fatal
159 #else
160 # define VALIDATE_POINTER_ERR CE_Failure
161 #endif
162 
163 #define VALIDATE_POINTER0(ptr, func) \
164  do { if( NULL == ptr ) \
165  { \
166  CPLErr const ret = VALIDATE_POINTER_ERR; \
167  CPLError( ret, CPLE_ObjectNull, \
168  "Pointer \'%s\' is NULL in \'%s\'.\n", #ptr, (func)); \
169  return; }} while(0)
170 
171 #define VALIDATE_POINTER1(ptr, func, rc) \
172  do { if( NULL == ptr ) \
173  { \
174  CPLErr const ret = VALIDATE_POINTER_ERR; \
175  CPLError( ret, CPLE_ObjectNull, \
176  "Pointer \'%s\' is NULL in \'%s\'.\n", #ptr, (func)); \
177  return (rc); }} while(0)
178 
179 #endif /* CPL_ERROR_H_INCLUDED */
void CPLPushErrorHandler(CPLErrorHandler)
Definition: cpl_error.cpp:1062
CPLErr CPLGetLastErrorType(void)
Definition: cpl_error.cpp:743
void _CPLAssert(const char *, const char *, int)
Definition: cpl_error.cpp:1192
void CPLSetCurrentErrorHandlerCatchDebug(int bCatchDebug)
Definition: cpl_error.cpp:1158
const char * CPLGetLastErrorMsg(void)
Definition: cpl_error.cpp:767
CPLErrorHandler CPLSetErrorHandlerEx(CPLErrorHandler, void *)
Definition: cpl_error.cpp:962
void CPLPopErrorHandler(void)
Definition: cpl_error.cpp:1120
void CPLDebug(const char *, const char *,...)
Definition: cpl_error.cpp:473
void CPLError(CPLErr eErrClass, CPLErrorNum err_no, const char *fmt,...)
Definition: cpl_error.cpp:199
void CPLErrorReset(void)
Definition: cpl_error.cpp:632
void CPLEmergencyError(const char *)
Definition: cpl_error.cpp:385
void * CPLGetErrorHandlerUserData(void)
Definition: cpl_error.cpp:153
CPLErrorNum CPLGetLastErrorNo(void)
Definition: cpl_error.cpp:719
CPLErrorHandler CPLSetErrorHandler(CPLErrorHandler)
Definition: cpl_error.cpp:1041
void CPLErrorSetState(CPLErr eErrClass, CPLErrorNum err_no, const char *pszMsg)
Definition: cpl_error.cpp:666
void CPLPushErrorHandlerEx(CPLErrorHandler, void *)
Definition: cpl_error.cpp:1086

Generated for GDAL by doxygen 1.8.13.