如何捕获和处理`_com_error`? [英] How do I catch and handle `_com_error`?

查看:86
本文介绍了如何捕获和处理`_com_error`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有这样的代码

IAcctMaintPtr acct(__uuidof(AcctMaint));
acct->GetAccountList(q);

现在此代码要求运行外部应用程序,否则在第一条语句后我会声明一个异常

Now this code requires an external application to be running otherwise after the first statement I get an exception stating

myapp.exe中0x7739c41f(KernelBase.dll)的未处理异常:Microsoft C ++异常:内存位置0x003ccefc出现_com_error.

Unhandled exception at 0x7739c41f (KernelBase.dll) in myapp.exe: Microsoft C++ exception: _com_error at memory location 0x003ccefc..

我试图 catch(const std :: exception&),但这似乎不起作用-没有捕获到异常.

I tried to catch( const std::exception& ) but that doesn't seem to work - the exception is not being caught.

关于如何捕获此异常的任何建议?

Any suggestion on how I could catch this exception ?

推荐答案

_com_error 不是从 std :: exception 派生的,但是您可以捕获它明确地:

_com_error does not derive from std::exception, but you can catch it explicitly:

try {
    IAcctMaintPtr acct(__uuidof(AcctMaint));
    acct->GetAccountList(q);
} catch (_com_error& x) {
    // Handle error in 'x'...
}

这篇关于如何捕获和处理`_com_error`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆