⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ugk_errhandle.cpp

📁 linux下一款GIS程序源码
💻 CPP
字号:
// ugk_errhandle.cpp ///////////////////////////////////////////////////////////////#include "ugk_errhandle.h"static char UGK_LastErrMsg[2000] = "";static int  UGK_LastErrNo = 0;static ErrType UGK_LastErrType = ET_None;static UGKErrorHandler UGK_ErrorHandler = UGKDefaultErrorHandler;/********************************************************************** *                          UGKError() **********************************************************************//** * Report an error. * * This function reports an error in a manner that can be hooked * and reported appropriate by different applications. * * The effect of this function can be altered by applications by installing * a custom error handling using UGKSetErrorHandler(). * * The eErrClass argument can have the value ET_Warning indicating that the * message is an informational warning, ET_Failure indicating that the * action failed, but that normal recover mechanisms will be used or * ET_Fatal meaning that a fatal error has occured, and that UGKError() * should not return.   * * The default behaviour of UGKError() is to report errors to stderr, * and to abort() after reporting a ET_Fatal error.  It is expected that * some applications will want to supress error reporting, and will want to * install a C++ exception, or longjmp() approach to no local fatal error * recovery. * * Regardless of how application error handlers or the default error * handler choose to handle an error, the error number, and message will * be stored for recovery with UGKGetLastErrorNo() and UGKGetLastErrorMsg(). */void    UGKError(ErrType eErrClass, int err_no, const char *fmt, ...){    va_list args;    /* Expand the error message      */    va_start(args, fmt);    UGKErrorV( eErrClass, err_no, fmt, args );    va_end(args);}/************************************************************************//*                             UGKErrorV()                              *//************************************************************************/void    UGKErrorV(ErrType eErrClass, int err_no, const char *fmt, va_list args ){    /* Expand the error message      */    vsprintf(UGK_LastErrMsg, fmt, args);    /* If the user provided his own error handling function, then call     * it, otherwise print the error to stderr and return.     */    UGK_LastErrNo = err_no;    UGK_LastErrType = eErrClass;	/*    if( CPLGetConfigOption("CPL_LOG_ERRORS",NULL) != NULL )        CPLDebug( "CPLError", "%s", gszCPLLastErrMsg );    */    if( UGK_ErrorHandler )        UGK_ErrorHandler(eErrClass, err_no, UGK_LastErrMsg);    if( eErrClass == ET_Fatal )        abort();		}/********************************************************************** *                          UGKErrorReset() **********************************************************************//** * Erase any traces of previous errors. * * This is normally used to ensure that an error which has been recovered * from does not appear to be still in play with high level functions. */void    UGKErrorReset(){    UGK_LastErrNo = UGKErr_None;    UGK_LastErrMsg[0] = '\0';    UGK_LastErrType = ET_None;}/********************************************************************** *                          UGKGetLastErrorNo() **********************************************************************//** * Fetch the last error number. * * This is the error number, not the error class. * * @return the error number of the last error to occur, or CPLE_None (0) * if there are no posted errors. */int     UGKGetLastErrorNo(){    return UGK_LastErrNo;}/********************************************************************** *                          UGKGetLastErrorType() **********************************************************************//** * Fetch the last error type. * * This is the error class, not the error number. * * @return the error number of the last error to occur, or CE_None (0) * if there are no posted errors. */ErrType UGKGetLastErrorType(){    return UGK_LastErrType;}/********************************************************************** *                          UGKGetLastErrorMsg() **********************************************************************//** * Get the last error message. * * Fetches the last error message posted with UGKError(), that hasn't * been cleared by UGKErrorReset().  The returned pointer is to an internal * string that should not be altered or freed. * * @return the last error message, or NULL if there is no posted error * message. */const char* UGKGetLastErrorMsg(){    return UGK_LastErrMsg;}/************************************************************************//*                       UGK_DefaultErrorHandler()                       *//************************************************************************/void UGKDefaultErrorHandler( ErrType eErrClass, int nError,                              const char * pszErrorMsg ){    static FILE *    fpLog;	fpLog = fopen("ErrLog.txt","wt");    if( eErrClass == ET_Debug )        fprintf( fpLog, "%s\n", pszErrorMsg );    else if( eErrClass == ET_Warning )        fprintf( fpLog, "Warning %d: %s\n", nError, pszErrorMsg );    else        fprintf( fpLog, "ERROR %d: %s\n", nError, pszErrorMsg );    fflush( fpLog );	fclose(fpLog);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -