Click here to Skip to main content
15,898,861 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: VC++ 7 compiler issue Pin
Sas280826-Sep-02 2:57
sussSas280826-Sep-02 2:57 
GeneralRe: VC++ 7 compiler issue Pin
SteveKing26-Sep-02 4:10
SteveKing26-Sep-02 4:10 
GeneralCView MDI or SDI projects Pin
ns26-Sep-02 2:13
ns26-Sep-02 2:13 
GeneralRe: CView MDI or SDI projects Pin
Tomasz Sowinski26-Sep-02 2:19
Tomasz Sowinski26-Sep-02 2:19 
General_DEBUG question Pin
ns26-Sep-02 2:03
ns26-Sep-02 2:03 
GeneralRe: _DEBUG question Pin
Tomasz Sowinski26-Sep-02 2:09
Tomasz Sowinski26-Sep-02 2:09 
GeneralRe: _DEBUG question Pin
ns26-Sep-02 2:16
ns26-Sep-02 2:16 
Generaltry-catch simple questions: Pin
ns26-Sep-02 1:55
ns26-Sep-02 1:55 
New to this so this is what I'm thinking it is:

In general CException will catch the errors; to go with 'new' CMemoryException will catch the errors. So if I have code as follows, do I have the right idea?

CAn I go through my code and put a try at the start of all my functions, and catches at the end?

What kind of error would CreateDispatch throw?

Where can you get information on the types of errors that various operations can produce?

_com_error : I havent found this in MSDN. If my MAkeDB function is a VB dll doing database stuff and something goes wrong in it, does the calling VC code get a _com_error?

    try
    {
      CString dataBaseName0 = "C:\\ImagesSep25.mdb";

  CString strFile0 = "C:\\Trainer\\final1.pma";

  CString imgFolder0 = "C:\\mines4";

  char* dataBaseName = new char[dataBaseName0.GetLength() +1];

  strcpy(dataBaseName, dataBaseName0);


  char* imgFolder = new char[imgFolder0.GetLength() +1];

  strcpy(imgFolder, imgFolder0);


  char* strFile = new char[strFile0.GetLength() +1];

  strcpy(strFile, strFile0);

  USES_CONVERSION;

   _bstr_t b_dataBaseName = A2W( dataBaseName ); //works in ANSI only.


  _bstr_t b_strFile = A2W(strFile);

  _bstr_t b_imgFolder = A2W(imgFolder);

  _CBCreator4 p;

  p.CreateDispatch("DBCreator4.Class1");

  p.MakeDB(b_strFile,b_dataBaseName,b_imgFolder,CMHandle
      delete[] etc
   }
   catch(CException &e)
   {

 CString ErrorStr;

 _bstr_t bstrSource(e.Source());

 _bstr_t bstrDescription(e.Description());

 ErrorStr.Format( " Error\n\tCode = %08lx\n\tCode meaning = %s\n\tSource = %s\n\tDescription = %s\n",
     e.Error(), e.ErrorMessage(), (LPCSTR)bstrSource, (LPCSTR)bstrDescription );
    #ifdef _DEBUG
  AfxMessageBox( ErrorStr, MB_OK | MB_ICONERROR );
    #endif
  }
catch (CMemoryException &e)
  {

CString ErrorStr;

_bstr_t bstrSource(e.Source());

_bstr_t bstrDescription(e.Description());

ErrorStr.Format( " Error\n\tCode = %08lx\n\tCode meaning = %s\n\tSource = %s\n\tDescription = %s\n",
e.Error(), e.ErrorMessage(), (LPCSTR)bstrSource, (LPCSTR)bstrDescription );
    #ifdef _DEBUG
   AfxMessageBox( ErrorStr, MB_OK | MB_ICONERROR );
    #endif
 })


Also I see that they have a MessageBox when errors happen when in Debug mode. In runtime mode, can I put in code in my catch block that does operations with the variables defined in the class or locally defined in the function the catch belongs to? , or do I have to pass them in? Like :

catch (_com_error &e)
   {
      //All the code from the catches above, plus 

      /#ifndef _DEBUG
      <code> m_db.Close(); </code>//this guy is visible to the catch? or does he need passed in the argument list of catch?
       #endif
           return;
    }



Thanks,
ns
GeneralHelp Wanted..!!!!! Pin
Renjith Ramachandran26-Sep-02 1:49
Renjith Ramachandran26-Sep-02 1:49 
GeneralRe: Help Wanted..!!!!! Pin
Anonymous26-Sep-02 1:59
Anonymous26-Sep-02 1:59 
GeneralRe: Help Wanted..!!!!! Pin
Renjith Ramachandran26-Sep-02 2:44
Renjith Ramachandran26-Sep-02 2:44 
GeneralRe: Help Wanted..!!!!! Pin
Anonymous26-Sep-02 3:18
Anonymous26-Sep-02 3:18 
GeneralRe: Help Wanted..!!!!! Pin
Renjith Ramachandran26-Sep-02 4:44
Renjith Ramachandran26-Sep-02 4:44 
GeneralRe: Help Wanted..!!!!! Pin
Anonymous26-Sep-02 6:08
Anonymous26-Sep-02 6:08 
GeneralProblem with exception... Pin
Raphael Kindt26-Sep-02 1:28
Raphael Kindt26-Sep-02 1:28 
GeneralRe: Problem with exception... Pin
Tomasz Sowinski26-Sep-02 1:35
Tomasz Sowinski26-Sep-02 1:35 
GeneralRe: Problem with exception... Pin
Raphael Kindt26-Sep-02 1:38
Raphael Kindt26-Sep-02 1:38 
GeneralRe: Problem with exception... Pin
Tomasz Sowinski26-Sep-02 1:47
Tomasz Sowinski26-Sep-02 1:47 
GeneralRe: Problem with exception... Pin
Raphael Kindt26-Sep-02 1:50
Raphael Kindt26-Sep-02 1:50 
GeneralRe: Problem with exception... Pin
Tomasz Sowinski26-Sep-02 1:59
Tomasz Sowinski26-Sep-02 1:59 
GeneralRe: Problem with exception... Pin
Anonymous26-Sep-02 2:22
Anonymous26-Sep-02 2:22 
GeneralRe: Problem with exception... Pin
Tomasz Sowinski26-Sep-02 2:31
Tomasz Sowinski26-Sep-02 2:31 
GeneralRe: Problem with exception... Pin
jmkhael26-Sep-02 1:45
jmkhael26-Sep-02 1:45 
GeneralRe: Problem with exception... Pin
Gunnar Bolle26-Sep-02 1:45
Gunnar Bolle26-Sep-02 1:45 
QuestionMaking accelerators work? Pin
Anonymous26-Sep-02 1:25
Anonymous26-Sep-02 1:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.