gpt4 book ai didi

c++ - 如何从向量化异常处理程序中获取更详细的异常信息?

转载 作者:行者123 更新时间:2023-11-30 01:53:57 25 4
gpt4 key购买 nike

在 Windows 应用程序中,如果您有 vector 异常处理程序:

LONG WINAPI VectoredExceptionHandler(PEXCEPTION_POINTERS exception)
{

}

...然后像这样添加...

AddVectoredExceptionHandler(1, VectoredExceptionHandler);

如果调用处理程序,您将获得有关异常的上下文信息,例如异常代码、exception->ExceptionRecord->ExceptionCode 和异常信息、exception->ExceptionRecord->ExceptionInformation 。您如何将此信息转换为字符串类型(例如 TCHAR)以告诉用户发生的确切问题是什么?例如,如果您要使用 WINAPI 方法编写一个小型转储,MiniDumpWriteDump 来编写一个转储文件,它将在转储文件中显示如下详细信息:

Exception Code: 0xC0000005

Exception Information: The thread tried to read from or write to a virtual address for which it does not have the appropriate access.

我可以很容易地转换异常代码,但是你如何获得如此详细的异常信息? exception->ExceptionRecord->ExceptionInformation,在我的环境中是一个 ULONG_PTR(运行此应用程序的 Windows 8.1 x64 内置 Release/x64 平台/多字节字符集)看起来当我将它写入 tstringstream 时就像这样:0000000000A2DF80

最佳答案

信息记录为 the documentation of the EXCEPTION_RECORD structure 的一部分:

ExceptionInformation

An array of additional arguments that describe the exception. ... The following table describes the exception codes whose array elements are defined.

EXCEPTION_ACCESS_VIOLATION

The first element of the array contains a read-write flag that indicates the type of operation that caused the access violation. If this value is zero, the thread attempted to read the inaccessible data. If this value is 1, the thread attempted to write to an inaccessible address. If this value is 8, the thread causes a user-mode data execution prevention (DEP) violation.

The second array element specifies the virtual address of the inaccessible data.

关于c++ - 如何从向量化异常处理程序中获取更详细的异常信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22548346/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com