OGR
cpl_error.h
Go to the documentation of this file.
1 /**********************************************************************
2  * $Id: cpl_error.h 26282 2013-08-08 21:15:36Z 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 void CPL_DLL CPLError(CPLErr eErrClass, int err_no, const char *fmt, ...) CPL_PRINT_FUNC_FORMAT (3, 4);
58 void CPL_DLL CPLErrorV(CPLErr, int, const char *, va_list );
59 void CPL_DLL CPLEmergencyError( const char * );
60 void CPL_DLL CPL_STDCALL CPLErrorReset( void );
61 int CPL_DLL CPL_STDCALL CPLGetLastErrorNo( void );
62 CPLErr CPL_DLL CPL_STDCALL CPLGetLastErrorType( void );
63 const char CPL_DLL * CPL_STDCALL CPLGetLastErrorMsg( void );
64 void CPL_DLL * CPL_STDCALL CPLGetErrorHandlerUserData(void);
65 void CPL_DLL CPLCleanupErrorMutex( void );
66 
67 typedef void (CPL_STDCALL *CPLErrorHandler)(CPLErr, int, const char*);
68 
69 void CPL_DLL CPL_STDCALL CPLLoggingErrorHandler( CPLErr, int, const char * );
70 void CPL_DLL CPL_STDCALL CPLDefaultErrorHandler( CPLErr, int, const char * );
71 void CPL_DLL CPL_STDCALL CPLQuietErrorHandler( CPLErr, int, const char * );
72 void CPLTurnFailureIntoWarning(int bOn );
73 
74 CPLErrorHandler CPL_DLL CPL_STDCALL CPLSetErrorHandler(CPLErrorHandler);
75 CPLErrorHandler CPL_DLL CPL_STDCALL CPLSetErrorHandlerEx(CPLErrorHandler, void*);
76 void CPL_DLL CPL_STDCALL CPLPushErrorHandler( CPLErrorHandler );
77 void CPL_DLL CPL_STDCALL CPLPushErrorHandlerEx( CPLErrorHandler, void* );
78 void CPL_DLL CPL_STDCALL CPLPopErrorHandler(void);
79 
80 void CPL_DLL CPL_STDCALL CPLDebug( const char *, const char *, ... ) CPL_PRINT_FUNC_FORMAT (2, 3);
81 void CPL_DLL CPL_STDCALL _CPLAssert( const char *, const char *, int );
82 
83 #ifdef DEBUG
84 # define CPLAssert(expr) ((expr) ? (void)(0) : _CPLAssert(#expr,__FILE__,__LINE__))
85 #else
86 # define CPLAssert(expr)
87 #endif
88 
89 CPL_C_END
90 
91 /*
92  * Helper macros used for input parameters validation.
93  */
94 #ifdef DEBUG
95 # define VALIDATE_POINTER_ERR CE_Fatal
96 #else
97 # define VALIDATE_POINTER_ERR CE_Failure
98 #endif
99 
100 #define VALIDATE_POINTER0(ptr, func) \
101  do { if( NULL == ptr ) \
102  { \
103  CPLErr const ret = VALIDATE_POINTER_ERR; \
104  CPLError( ret, CPLE_ObjectNull, \
105  "Pointer \'%s\' is NULL in \'%s\'.\n", #ptr, (func)); \
106  return; }} while(0)
107 
108 #define VALIDATE_POINTER1(ptr, func, rc) \
109  do { if( NULL == ptr ) \
110  { \
111  CPLErr const ret = VALIDATE_POINTER_ERR; \
112  CPLError( ret, CPLE_ObjectNull, \
113  "Pointer \'%s\' is NULL in \'%s\'.\n", #ptr, (func)); \
114  return (rc); }} while(0)
115 
116 /* ==================================================================== */
117 /* Well known error codes. */
118 /* ==================================================================== */
119 
120 #define CPLE_None 0
121 #define CPLE_AppDefined 1
122 #define CPLE_OutOfMemory 2
123 #define CPLE_FileIO 3
124 #define CPLE_OpenFailed 4
125 #define CPLE_IllegalArg 5
126 #define CPLE_NotSupported 6
127 #define CPLE_AssertionFailed 7
128 #define CPLE_NoWriteAccess 8
129 #define CPLE_UserInterrupt 9
130 #define CPLE_ObjectNull 10
131 
132 /* 100 - 299 reserved for GDAL */
133 
134 #endif /* CPL_ERROR_H_INCLUDED */
void CPLPushErrorHandler(CPLErrorHandler)
Definition: cpl_error.cpp:841
CPLErr CPLGetLastErrorType(void)
Definition: cpl_error.cpp:539
void _CPLAssert(const char *, const char *, int)
Definition: cpl_error.cpp:924
const char * CPLGetLastErrorMsg(void)
Definition: cpl_error.cpp:561
CPLErrorHandler CPLSetErrorHandlerEx(CPLErrorHandler, void *)
Definition: cpl_error.cpp:746
void CPLPopErrorHandler(void)
Definition: cpl_error.cpp:892
void CPLDebug(const char *, const char *,...)
Definition: cpl_error.cpp:377
void CPLErrorReset(void)
Definition: cpl_error.cpp:494
void CPLEmergencyError(const char *)
Definition: cpl_error.cpp:289
void * CPLGetErrorHandlerUserData(void)
Definition: cpl_error.cpp:115
CPLErrorHandler CPLSetErrorHandler(CPLErrorHandler)
Definition: cpl_error.cpp:820
void CPLPushErrorHandlerEx(CPLErrorHandler, void *)
Definition: cpl_error.cpp:865
int CPLGetLastErrorNo(void)
Definition: cpl_error.cpp:518
void CPLError(CPLErr eErrClass, int err_no, const char *fmt,...)
Definition: cpl_error.cpp:157

Generated for GDAL by doxygen 1.8.11.