C++ Builder 参考手册 ➙ System::Sysutils ➙ ExceptionErrorMessage
获取产生异常的错误信息,用于 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);
}
}
运行结果:
![](https://img.haomeiwen.com/i19822773/871124b1111aa8a6.png)
相关:
- 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::Sysutils ➙ ExceptionErrorMessage
网友评论