GDAL
cpl_error.h
Go to the documentation of this file.
00001 /**********************************************************************
00002  * $Id: cpl_error.h 36675 2016-12-04 11:10:10Z rouault $
00003  *
00004  * Name:     cpl_error.h
00005  * Project:  CPL - Common Portability Library
00006  * Purpose:  CPL Error handling
00007  * Author:   Daniel Morissette, danmo@videotron.ca
00008  *
00009  **********************************************************************
00010  * Copyright (c) 1998, Daniel Morissette
00011  *
00012  * Permission is hereby granted, free of charge, to any person obtaining a
00013  * copy of this software and associated documentation files (the "Software"),
00014  * to deal in the Software without restriction, including without limitation
00015  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00016  * and/or sell copies of the Software, and to permit persons to whom the
00017  * Software is furnished to do so, subject to the following conditions:
00018  *
00019  * The above copyright notice and this permission notice shall be included
00020  * in all copies or substantial portions of the Software.
00021  *
00022  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00023  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00024  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00025  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00026  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00027  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00028  * DEALINGS IN THE SOFTWARE.
00029  ****************************************************************************/
00030 
00031 #ifndef CPL_ERROR_H_INCLUDED
00032 #define CPL_ERROR_H_INCLUDED
00033 
00034 #include "cpl_port.h"
00035 
00036 #include <stdarg.h>
00037 #include <stddef.h>
00038 
00039 /*=====================================================================
00040                    Error handling functions (cpl_error.c)
00041  =====================================================================*/
00042 
00049 CPL_C_START
00050 
00052 typedef enum
00053 {
00054     CE_None = 0,
00055     CE_Debug = 1,
00056     CE_Warning = 2,
00057     CE_Failure = 3,
00058     CE_Fatal = 4
00059 } CPLErr;
00060 
00061 /* ==================================================================== */
00062 /*      Well known error codes.                                         */
00063 /* ==================================================================== */
00064 
00065 #ifdef STRICT_CPLERRORNUM_TYPE
00066 
00067 /* This is not appropriate for the general case, as there are parts */
00068 /* of GDAL which use custom error codes, but this can help diagnose confusions */
00069 /* between CPLErr and CPLErrorNum */
00070 typedef enum
00071 {
00072   CPLE_None,
00073   CPLE_AppDefined,
00074   CPLE_OutOfMemory,
00075   CPLE_FileIO,
00076   CPLE_OpenFailed,
00077   CPLE_IllegalArg,
00078   CPLE_NotSupported,
00079   CPLE_AssertionFailed,
00080   CPLE_NoWriteAccess,
00081   CPLE_UserInterrupt,
00082   CPLE_ObjectNull,
00083   CPLE_HttpResponse,
00084   CPLE_HttpResponse,
00085   CPLE_AWSBucketNotFound,
00086   CPLE_AWSObjectNotFound,
00087   CPLE_AWSAccessDenied,
00088   CPLE_AWSInvalidCredentials,
00089   CPLE_AWSSignatureDoesNotMatch,
00090 } CPLErrorNum;
00091 
00092 #else
00093 
00095 typedef int CPLErrorNum;
00096 
00098 #define CPLE_None                       0
00099 
00100 #define CPLE_AppDefined                 1
00101 
00102 #define CPLE_OutOfMemory                2
00103 
00104 #define CPLE_FileIO                     3
00105 
00106 #define CPLE_OpenFailed                 4
00107 
00108 #define CPLE_IllegalArg                 5
00109 
00110 #define CPLE_NotSupported               6
00111 
00112 #define CPLE_AssertionFailed            7
00113 
00114 #define CPLE_NoWriteAccess              8
00115 
00116 #define CPLE_UserInterrupt              9
00117 
00118 #define CPLE_ObjectNull                 10
00119 
00120 /*
00121  * Filesystem-specific errors
00122  */
00124 #define CPLE_HttpResponse               11
00125 
00126 #define CPLE_AWSBucketNotFound          12
00127 
00128 #define CPLE_AWSObjectNotFound          13
00129 
00130 #define CPLE_AWSAccessDenied            14
00131 
00132 #define CPLE_AWSInvalidCredentials      15
00133 
00134 #define CPLE_AWSSignatureDoesNotMatch    16
00135 
00136 /* 100 - 299 reserved for GDAL */
00137 
00138 #endif
00139 
00140 void CPL_DLL CPLError(CPLErr eErrClass, CPLErrorNum err_no, CPL_FORMAT_STRING(const char *fmt), ...)  CPL_PRINT_FUNC_FORMAT (3, 4);
00141 void CPL_DLL CPLErrorV(CPLErr, CPLErrorNum, const char *, va_list );
00142 void CPL_DLL CPLEmergencyError( const char * ) CPL_NO_RETURN;
00143 void CPL_DLL CPL_STDCALL CPLErrorReset( void );
00144 CPLErrorNum CPL_DLL CPL_STDCALL CPLGetLastErrorNo( void );
00145 CPLErr CPL_DLL CPL_STDCALL CPLGetLastErrorType( void );
00146 const char CPL_DLL * CPL_STDCALL CPLGetLastErrorMsg( void );
00147 void CPL_DLL * CPL_STDCALL CPLGetErrorHandlerUserData(void);
00148 void CPL_DLL CPLErrorSetState( CPLErr eErrClass, CPLErrorNum err_no, const char* pszMsg );
00150 void CPL_DLL CPLCleanupErrorMutex( void );
00154 typedef void (CPL_STDCALL *CPLErrorHandler)(CPLErr, CPLErrorNum, const char*);
00155 
00156 void CPL_DLL CPL_STDCALL CPLLoggingErrorHandler( CPLErr, CPLErrorNum, const char * );
00157 void CPL_DLL CPL_STDCALL CPLDefaultErrorHandler( CPLErr, CPLErrorNum, const char * );
00158 void CPL_DLL CPL_STDCALL CPLQuietErrorHandler( CPLErr, CPLErrorNum, const char * );
00159 void CPLTurnFailureIntoWarning( int bOn );
00160 
00161 CPLErrorHandler CPL_DLL CPL_STDCALL CPLSetErrorHandler( CPLErrorHandler );
00162 CPLErrorHandler CPL_DLL CPL_STDCALL CPLSetErrorHandlerEx( CPLErrorHandler, void* );
00163 void CPL_DLL CPL_STDCALL CPLPushErrorHandler( CPLErrorHandler );
00164 void CPL_DLL CPL_STDCALL CPLPushErrorHandlerEx( CPLErrorHandler, void* );
00165 void CPL_DLL CPL_STDCALL CPLSetCurrentErrorHandlerCatchDebug( int bCatchDebug );
00166 void CPL_DLL CPL_STDCALL CPLPopErrorHandler(void);
00167 
00168 #ifdef WITHOUT_CPLDEBUG
00169 #define CPLDebug(...)  /* Eat all CPLDebug calls. */
00170 #else
00171 void CPL_DLL CPL_STDCALL CPLDebug(const char *, CPL_FORMAT_STRING(const char *), ...)
00172     CPL_PRINT_FUNC_FORMAT(2, 3);
00173 #endif
00174 
00175 void CPL_DLL CPL_STDCALL _CPLAssert( const char *, const char *, int ) CPL_NO_RETURN;
00176 
00177 #ifdef DEBUG
00178 
00179 #  define CPLAssert(expr)  ((expr) ? (void)(0) : _CPLAssert(#expr,__FILE__,__LINE__))
00180 #else
00181 
00182 #  define CPLAssert(expr)
00183 #endif
00184 
00185 CPL_C_END
00186 
00188 /*
00189  * Helper macros used for input parameters validation.
00190  */
00191 #ifdef DEBUG
00192 #  define VALIDATE_POINTER_ERR CE_Fatal
00193 #else
00194 #  define VALIDATE_POINTER_ERR CE_Failure
00195 #endif
00196 
00199 #define VALIDATE_POINTER0(ptr, func) \
00200    do { if( NULL == ptr ) \
00201       { \
00202         CPLErr const ret = VALIDATE_POINTER_ERR; \
00203         CPLError( ret, CPLE_ObjectNull, \
00204            "Pointer \'%s\' is NULL in \'%s\'.\n", #ptr, (func)); \
00205          return; }} while(0)
00206 
00208 #define VALIDATE_POINTER1(ptr, func, rc) \
00209    do { if( NULL == ptr ) \
00210       { \
00211           CPLErr const ret = VALIDATE_POINTER_ERR; \
00212           CPLError( ret, CPLE_ObjectNull, \
00213            "Pointer \'%s\' is NULL in \'%s\'.\n", #ptr, (func)); \
00214         return (rc); }} while(0)
00215 
00216 #endif /* CPL_ERROR_H_INCLUDED */

Generated for GDAL by doxygen 1.7.6.1.