美文网首页
ExceptionErrorMessage - C++ Buil

ExceptionErrorMessage - C++ Buil

作者: 玄坴 | 来源:发表于2021-11-02 09:56 被阅读0次

    C++ Builder 参考手册System::SysutilsExceptionErrorMessage


    获取产生异常的错误信息,用于 ShowException 内部调用的函数

    头文件:#include <System.SysUtils.hpp>
    命名空间:System::Sysutils
    函数原型:

    int __fastcall ExceptionErrorMessage(System::TObject* ExceptObject, void * ExceptAddr, System::WideChar * Buffer, int Size);
    

    参数:

    • ExceptObject:产生异常的对象;
    • ExceptAddr:产生异常的地址;
    • Buffer:缓存地址,用于返回异常信息;
    • Size:缓存大小;

    返回值:

    • 获取产生异常的错误信息,通过 Buffer 参数返回,函数返回异常信息的实际长度;
    • 用于 System::Sysutils::ShowException 内部调用的函数。

    例:

    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
        try
        {
            HANDLE hFile = CreateFile(L"D:\\Temp\\Hsuanlu.txt", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
            CheckOSError(GetLastError());
            CloseHandle(hFile);
        }
        catch(...)
        {
            TObject *pObj = System::ExceptObject();
            void *pAddr = System::ExceptAddr();
            System::WideChar pBuf[1024];
            ExceptionErrorMessage(pObj,pAddr,pBuf,1024);
            ShowMessage(pBuf);
        }
    }
    

    运行结果:

    运行结果

    相关:

    • System::Sysutils::ShowException
    • System::Sysutils::ExceptionErrorMessage
    • System::Sysutils::RaiseLastOSError
    • System::Sysutils::CheckOSError
    • System::Sysutils::Win32Check
    • System::Sysutils::OutOfMemoryError
    • System::Sysutils::Abort
    • System::Sysutils::EAbort
    • System::Sysutils
    • System::ExceptObject
    • System::ExceptAddr
    • System
    • Vcl::Forms::TApplication::ShowException

    C++ Builder 参考手册System::SysutilsExceptionErrorMessage

    相关文章

      网友评论

          本文标题:ExceptionErrorMessage - C++ Buil

          本文链接:https://www.haomeiwen.com/subject/zfmdahtx.html