简体   繁体   English

使用 SEH 保护我的代码免受第三方 COM 对象抛出的异常是否合理

[英]Is it reasonable to use SEH to protect my code from exceptions thrown by third party COM objects

I'm protecting my own C++ code (Windows x86) from exceptions in a third party COM object and logging those exceptions using the following SEH pseudocode.我正在保护我自己的 C++ 代码 (Windows x86) 免受第三方 COM object 中的异常,并使用以下 SEH 伪代码记录这些异常。

__try {
    hr = m_ComObj->SomeFunc();
} __except ( LogExceptionInfo(GetExceptionCode(), GetExceptionInformation()) ) {
    hr = E_UNEXPECTED;
    m_ComObjCrashed = true;
}

Is this approach likely to catch exceptions that would be handled if the SEH code wasn't present?如果 SEH 代码不存在,这种方法是否可能捕获将被处理的异常?

An MSDN article below mentions that the default unhandled exception filter will catch and fix the case where code writes to memory in loaded resources.下面的一篇 MSDN 文章提到默认的未处理异常过滤器将捕获并修复代码写入加载资源中的 memory 的情况。 Are there other cases where using SEH will interfere with desirable default OS behaviour?在其他情况下,使用 SEH 是否会干扰理想的默认操作系统行为?

A Crash Course on the Depths of Win32™ Structured Exception Handling 深入了解 Win32™ 结构化异常处理的速成课程

Yes it's quite reasonable.是的,这很合理。

It will catch all exceptions that are unhandled in the COM function它将捕获 COM function 中未处理的所有异常

I don't see any interference-related problems with default OS behaviour我没有看到任何与默认操作系统行为有关的干扰问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM