Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC
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);
 
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;
}
Posted 22-Dec-12 8:26am
Comments
Richard MacCutchan at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
Comments
Schehaider_Aymen at 23-Dec-12 10:24am
   
Thank you. I used another trick : generic exception :) but your's is better.
jibesh at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 499
1 Nirav Prabtani 338
2 OriginalGriff 175
3 _Amy 170
4 PIEBALDconsult 160
0 OriginalGriff 7,640
1 Sergey Alexandrovich Kryukov 6,836
2 Maciej Los 3,919
3 Peter Leow 3,698
4 CHill60 2,742


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 22 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100