程序崩溃,即使使用Assert(HRESULT) [英] Program crashes even with Assert (HRESULT)

查看:148
本文介绍了程序崩溃,即使使用Assert(HRESULT)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个很大的问题,希望能得到你的帮助。我有一个名为 pRstEmployDB _RecordsetPtr 变量。在我的代码中,我有一行打开Recordset



Hi all,

I have a big problem that I hope get help from you. I have a _RecordsetPtr variable called pRstEmployDB. In my code I have a line to open the Recordset

pRstEmployDB->Open("SOCIETE", _variant_t((IDispatch *) theApp.pConEmployDB, true),  adOpenStatic, adLockReadOnly, adCmdTable);





问题是当这个功能崩溃时(Acces Violation)它会显示一个messageBox来表示错误发生了,崩溃了。我怎么能抓住错误,所以程序将不再崩溃并被关闭?



我试图使用ASSERT(... == S_OK)但也崩溃了。



我也尝试过这种方式,但没有希望





the probleme is when this fucntion crashes (Acces Violation) it shows a messageBox to say that an error happened and crashes. How could i Catch the error so the program will no longer crashes and be closed?

I tried to use ASSERT(... ==S_OK) but crashes too.

I tried this way too, but no hope

Try
{
 pRstEmployDB->Open("SOCIETE", _variant_t((IDispatch *) theApp.pConEmployDB, true),   adOpenStatic, adLockReadOnly, adCmdTable);
}
catch (CException* e)
{
  return FALSE;
}

推荐答案

它绕过catch的原因是因为pRstEmplyDB抛出的异常是 _com_error 而不是 CEXception 类型



用_com_error替换CException你的问题将得到解决。



了解更多@ 关于_pRecordSetPtr [ ^ ]
The reason why it bypass the catch is because the exception thrown by pRstEmplyDB is _com_error and not CEXception type

replace CException with _com_error your problem will be solved.

read more @About _pRecordSetPtr[^]


这篇关于程序崩溃,即使使用Assert(HRESULT)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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