Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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


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

C#
Try
{
 pRstEmployDB->Open("SOCIETE", _variant_t((IDispatch *) theApp.pConEmployDB, true),   adOpenStatic, adLockReadOnly, adCmdTable);
}
catch (CException* e)
{
  return FALSE;
}
Posted
Comments
Richard MacCutchan 23-Dec-12 6:12am    
You cannot catch Access violation, as it is a hard error. You need to debug your program and figure out what is causing the fault.

1 solution

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[^]
 
Share this answer
 
Comments
Schehaider_Aymen 23-Dec-12 10:24am    
Thank you. I used another trick : generic exception :) but your's is better.
Jibesh 23-Dec-12 12:09pm    
You Welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900