Writing SEH translator

Writing SEH translator

本文关键字:translator SEH Writing      更新时间:2023-10-16
class seh_exception : public std::exception {
public:   
    seh_exception(UINT se_code, PEXCEPTION_POINTERS se_info);
    seh_exception(const seh_exception& old);
    ~seh_exception();
    const char *what() const;
};
void translate_seh_exception(UINT se_code, PEXCEPTION_POINTERS se_info) {
    throw seh_exception(se_code, se_info);
}

现在,我在构造函数中该怎么办?我找不到有关*se_info存在多长时间的任何信息,这意味着我可能不应该仅将se_info保存在私有字段中以供以后使用 - 我应该深入复制它。也许不是?

what()是什么?我应该想起基础的按需字符串吗?同样,在这种情况下,在构造函数中分配内存似乎不是一个好主意。

我目前已经实施了IT存储se_codese_info,而无需任何深层复制,并在构造函数中生成格式的消息,尽管我不知道它是否真的是 quay quest

我打算在"捕获,记录发生的事情,终止"方案中使用它。

您不需要自己的课程就可以实现这一目标,只需扔PEXCEPTION_POINTERS即可。se_code也可以在se_info->ExceptionRecord->ExceptionCode上找到。

所以最简单的处理程序只是;

void translate_seh_exception(UINT se_code, PEXCEPTION_POINTERS se_info) {
    throw se_info;
}

您可以catch(PEXCEPTION_POINTERS se_info)

保证EXCEPTION_POINTERScatch块的持续时间内存在,这是您需要的时间。根据文档,对于每个捕获块,调用了一次转换器函数一次,即,它必须重新换装包含try/catch块的每个函数的SEH例外。