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

📄 log.cpp

📁 vc ADO 连接数据库
💻 CPP
📖 第 1 页 / 共 2 页
字号:
            case CArchiveException::badSchema:
                Log( _T("\t Cause = BadSchema (Tried to read an object with a different version of the class)." ) );
                break;
            default:
                Log( _T("\t Cause = Uknown)." ) );
            }
        }

        if ( e->IsKindOf( RUNTIME_CLASS( CFileException ) ) == TRUE )
        {
            CFileException *eFile = (CFileException *) e;

            switch( eFile->m_cause )
            {
            case CFileException::none:
                Log( _T("\t Cause = None (No error occurred.)") );
                break;
            case CFileException::generic:
                Log( _T("\t Cause = Generic (An unspecified error occurred.)") );
                break;
            case CFileException::fileNotFound:
                Log( _T("\t Cause = FileNotFound (The file could not be located.)") );
                break;
            case CFileException::badPath:
                Log( _T("\t Cause = BadPath (All or part of the path is invalid.)") );
                break;
            case CFileException::tooManyOpenFiles:
                Log( _T("\t Cause = TooManyOpenFiles (The permitted number of open files was exceeded.)") );
                break;
            case CFileException::accessDenied:
                Log( _T("\t Cause = AccessDenied (The file could not be accessed.)") );
                break;
            case CFileException::invalidFile: 
                Log( _T("\t Cause = InvalidFile (There was an attempt to use an invalid file handle.)") );
                break;
            case CFileException::removeCurrentDir:
                Log( _T("\t Cause = RemoveCurrentDir (The current working directory cannot be removed.)") );
                break;
            case CFileException::directoryFull:
                Log( _T("\t Cause = DirectoryFull (There are no more directory entries.)") );
                break;
            case CFileException::badSeek:
                Log( _T("\t Cause = BadSeek (There was an error trying to set the file pointer.)") );
                break;
            case CFileException::hardIO: 
                Log( _T("\t Cause = HardIO (There was a hardware error.)") );
                break;
            case CFileException::sharingViolation:
                Log( _T("\t Cause = SharingViolation (SHARE.EXE was not loaded, or a shared region was locked.)") );
                break;
            case CFileException::lockViolation:
                Log( _T("\t Cause = LockingViolation (There was an attempt to lock a region that was already locked.)") );
                break;
            case CFileException::diskFull:
                Log( _T("\t Cause = DiskFull (The disk is full.)") );
                break;
            case CFileException::endOfFile:
                Log( _T("\t Cause = EndOfFile (The end of file was reached.)") );
                break;
            default:
                Log( _T("\t Cause = Unrecognized Cause (Unknown.)") );
            }
        }

        if ( e->IsKindOf( RUNTIME_CLASS( COleException ) ) == TRUE )
        {
            COleException *eOle = (COleException *) e;

            Log( _T("\t SCODE = %ld"), eOle->m_sc );
        }

        if ( e->IsKindOf( RUNTIME_CLASS( COleDispatchException ) ) == TRUE )
        {
            // Makes things a lot cleaner below
            COleDispatchException *eOleDisp = (COleDispatchException *) e;

            // Indicate Exception Cause
            Log( _T("\t IDispatchErr:\t %ld"), eOleDisp->m_wCode );
            Log( _T("\t Description:\t %s"),   (LPCTSTR) eOleDisp->m_strDescription );
            Log( _T("\t HlpFile:\t %s"),       (LPCTSTR) eOleDisp->m_strHelpFile );
            Log( _T("\t HlpContext:\t %ld"),   eOleDisp->m_dwHelpContext );
            Log( _T("\t Application:\t %ld"),  eOleDisp->m_strSource );
        }
    }
    catch( CException *e2 )
    {
        Log( _T("MFC Exception was generated during logging of MFC Exception") );
        e2->Delete();
    }
    catch( SEH_Exception )
    {
        Log( _T("Win32 Exception was generated during logging of MFC Exception") );
    }
    catch(...)
    {
        Log( _T("Unidentified Exception was generated during logging of MFC Exception") );
    }

    // Delete Exception
    e->Delete();

    // Let user know we failed!
    if ( bVerbose == TRUE )
        AfxMessageBox( _T("OPERATION FAILED:  See Errors for details.") );
}
       

void LogException
(
    SEH_Exception &e,               // Win32 SEH Class
    LPCSTR        lpszTimeStamp,    // Date & Time    
    LPCSTR        lpszFile,         // File Name
    int           nLine             // Line #
)
{
    Log( _T("Win32 Structured Exception thrown:") );
    Log( STR_FILE,          (LPCTSTR) lpszFile );
    Log( _T("\t LINE #%d"), nLine );
    Log( STR_TIME,          (LPCTSTR) lpszTimeStamp );

    LogExceptionEx( e );
}

void LogException
(
    SEH_Exception &e                // Win32 SEH Class
)
{
    // Just in case exception handling code throws an exception
    Log( _T("Win32 Structured Exception thrown:") );

    LogExceptionEx( e );
}

static void LogExceptionEx
(
    SEH_Exception &e                // Win32 SEH Class
)
{
    // Just in case exception handling code throws an exception
    try
    {
        switch( e.getSeHNumber() )
        {
        case EXCEPTION_ACCESS_VIOLATION:
            Log( _T("\t EXCEPTION_ACCESS_VIOLATION:  The thread attempted to read from or write to a virtual address for which it does not have the appropriate access.") );
            break;
        case EXCEPTION_BREAKPOINT:
            Log( _T("\t EXCEPTION_BREAKPOINT:  A breakpoint was encountered.") );
            break;
        case EXCEPTION_DATATYPE_MISALIGNMENT:
            Log( _T("\t EXCEPTION_DATATYPE_MISALIGNMENT:  The thread attempted to read or write data that is misaligned on hardware that does not provide alignment. For example, 16-bit values must be aligned on 2-byte boundaries, 32-bit values on 4-byte boundaries, and so on.") );
            break;
        case EXCEPTION_SINGLE_STEP:
            Log( _T("\t EXCEPTION_SINGLE_STEP:  A trace trap or other single-instruction mechanism signaled that one instruction has been executed.") );
            break;
        case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
            Log( _T("\t EXCEPTION_ARRAY_BOUNDS_EXCEEDED:  The thread attempted to access an array element that is out of bounds, and the underlying hardware supports bounds checking.") );
            break;
        case EXCEPTION_FLT_DENORMAL_OPERAND:
            Log( _T("\t EXCEPTION_FLT_DENORMAL_OPERAND:  One of the operands in a floating-point operation is denormal. A denormal value is one that is too small to represent as a standard floating-point value.") );
            break;
        case EXCEPTION_FLT_DIVIDE_BY_ZERO:
            Log( _T("\t EXCEPTION_FLT_DIVIDE_BY_ZERO:  The thread attempted to divide a floating-point value by a floating-point divisor of zero.") );
            break;
        case EXCEPTION_FLT_INEXACT_RESULT:
            Log( _T("\t EXCEPTION_FLT_INEXACT_RESULT:  The result of a floating-point operation cannot be represented exactly as a decimal fraction.") );
            break;
        case EXCEPTION_FLT_INVALID_OPERATION:
            Log( _T("\t EXCEPTION_FLT_INVALID_OPERATION:  This exception represents any floating-point exception not included in this list.") );
            break;
        case EXCEPTION_FLT_OVERFLOW:
            Log( _T("\t EXCEPTION_FLT_OVERFLOW:  The exponent of a floating-point operation is greater than the magnitude allowed by the corresponding type.") );
            break;
        case EXCEPTION_FLT_STACK_CHECK:
            Log( _T("\t EXCEPTION_FLT_STACK_CHECK:  The stack overflowed or underflowed as the result of a floating-point operation.") );
            break;
        case EXCEPTION_FLT_UNDERFLOW:
            Log( _T("\t EXCEPTION_FLT_UNDERFLOW:  The exponent of a floating-point operation is less than the magnitude allowed by the corresponding type.") );
            break;
        case EXCEPTION_INT_DIVIDE_BY_ZERO:
            Log( _T("\t EXCEPTION_INT_DIVIDE_BY_ZERO:  The thread attempted to divide an integer value by an integer divisor of zero.") );
            break;
        case EXCEPTION_INT_OVERFLOW:
            Log( _T("\t EXCEPTION_INT_OVERFLOW:  The result of an integer operation caused a carry out of the most significant bit of the result.") );
            break;
        case EXCEPTION_PRIV_INSTRUCTION:
            Log( _T("\t EXCEPTION_PRIV_INSTRUCTION:  The thread attempted to execute an instruction whose operation is not allowed in the current machine mode.") );
            break;
        case EXCEPTION_NONCONTINUABLE_EXCEPTION:
            Log( _T("\t EXCEPTION_NONCONTINUABLE_EXCEPTION:  The thread attempted to continue execution after a noncontinuable exception occurred.") );
            break;
        case EXCEPTION_IN_PAGE_ERROR:
            Log( _T("\t EXCEPTION_IN_PAGE_ERROR:  The thread tried to access a page that was not present, and the system was unable to load the page. For example, this exception might occur if a network connection is lost while running a program over the network.") );
            break;
        case EXCEPTION_ILLEGAL_INSTRUCTION:
            Log( _T("\t EXCEPTION_ILLEGAL_INSTRUCTION:  The thread tried to execute an invalid instruction.") );
            break;
        case EXCEPTION_STACK_OVERFLOW:
            Log( _T("\t EXCEPTION_STACK_OVERFLOW:  The thread used up its stack.") );
            break;
        case EXCEPTION_INVALID_DISPOSITION:
            Log( _T("\t EXCEPTION_INVALID_DISPOSITION:  An exception handler returned an invalid disposition to the exception dispatcher. Programmers using a high-level language such as C should never encounter this exception.") );
            break;
        case EXCEPTION_GUARD_PAGE:
            Log( _T("\t EXCEPTION_GUARD_PAGE:  A very deep and not well documented Windows Memory Management error has occured.") );
            break;
        case EXCEPTION_INVALID_HANDLE:
            Log( _T("\t EXCEPTION_INVALID_HANDLE:  A very deep and not well documented Windows Memory Management error has occured.") );
            break;
        default:
            Log( _T("\t Unknown Win32 Exception Code" ) );
            break;
        }
    }
    catch( CException *e2 )
    {
        Log( _T("MFC Exception was generated during logging of Win32 Structured Exception") );
        e2->Delete();
    }
    catch( SEH_Exception )
    {
        Log( _T("Win32 Exception was generated during logging of Win32 Structured Exception") );
    }
    catch(...)
    {
        Log( _T("Unidentified Exception was generated during logging of Win32 Structured Exception") );
    }

    // Let user know we failed
    if ( bVerbose == TRUE )
        AfxMessageBox( _T("OPERATION FAILED:  See Errors for details.") );
}

    

#if _MSC_VER >= 1100
    void LogException
    ( 
        _com_error    &e,               // #import excep class
        LPCSTR        lpszTimeStamp,    // Date & Time    
        LPCSTR        lpszFile,         // File Name
        int           nLine        
    )
    {
        Log( _T("_com_error Exception thrown for classes generated by #import") );
        Log( STR_FILE,          (LPCTSTR) lpszFile );
        Log( _T("\t LINE #%d"), nLine );
        Log( STR_TIME,          (LPCTSTR) lpszTimeStamp );

        LogExceptionEx( e );
    }

    void LogException
    ( 
        _com_error    &e               // #import excep class
    )
    {
        Log( _T("_com_error Exception thrown for classes generated by #import") );

        LogExceptionEx( e );
    }

    static void LogExceptionEx( _com_error &e )
    {
        try
        {
            _bstr_t bstrSource(e.Source());
            _bstr_t bstrDescription(e.Description());

            Log( _T("\tCode = %08lx"), e.Error());
            Log( STR_MEANING,            e.ErrorMessage());
            Log( STR_SOURCE,             (LPCTSTR) bstrSource);
            Log( STR_DESCRIPTION,        (LPCTSTR) bstrDescription);
        }
        catch( CException *e2 )
        {
            Log( _T("MFC Exception was generated during logging of Unidentified Exception") );
            e2->Delete();
        }
        catch( SEH_Exception )
        {
            Log( _T("Win32 Exception was generated during logging of Unidentified Exception") );
        }
        catch(...)
        {
            Log( _T("Unidentified Exception was generated during logging of Unidentified Exception") );
        }

        // Let user know we failed
        if ( bVerbose == TRUE )
            AfxMessageBox( _T("OPERATION FAILED:  See Errors for details.") );

    }
#endif
        
void LogException( void )
{
    try
    {
        Log( _T("Unidentified Exception thrown") );
    }
    catch( CException *e2 )
    {
        Log( _T("MFC Exception was generated during logging of Unidentified Exception") );
        e2->Delete();
    }
    catch( SEH_Exception )
    {
        Log( _T("Win32 Exception was generated during logging of Unidentified Exception") );
    }
    catch(...)
    {
        Log( _T("Unidentified Exception was generated during logging of Unidentified Exception") );
    }

    // Let user know we failed
    if ( bVerbose == TRUE )
        AfxMessageBox( _T("OPERATION FAILED:  See Errors for details.") );
}

void LogException
(
    LPCSTR        lpszTimeStamp,    // Date & Time    
    LPCSTR        lpszFile,         // File Name
    int           nLine             // Line #
)
{
    try
    {
        Log( _T("Unidentified Exception thrown") );
        Log( STR_FILE,          (LPCTSTR) lpszFile );
        Log( _T("\t LINE #%d"), nLine );
        Log( STR_TIME,          (LPCTSTR) lpszTimeStamp );
    }
    catch( CException *e2 )
    {
        Log( _T("MFC Exception was generated during logging of Unidentified Exception") );
        e2->Delete();
    }
    catch( SEH_Exception )
    {
        Log( _T("Win32 Exception was generated during logging of Unidentified Exception") );
    }
    catch(...)
    {
        Log( _T("Unidentified Exception was generated during logging of Unidentified Exception") );
    }

    // Let user know we failed
    if ( bVerbose == TRUE )
        AfxMessageBox( _T("OPERATION FAILED:  See Errors for details.") );
}

⌨️ 快捷键说明

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