Another unhandled exception...

Here is my code:

try
{
      rs->Open(CRecordset::snapshot, csSQL);
      if (rs->IsBOF() && rs->IsEOF())
            return 0;
      rs->MoveFirst();
      rs->GetFieldValue("table_name", varValue);
      cout << *varValue.m_pstring << endl;
}
catch (CException cexcpt)
{
      cout << "here 1" << endl;
}
catch (CArchiveException carchiveexcpt)
{
      cout << "here 2" << endl;
}
catch (CDBException cdbexcpt)
{
      cout << "here 3" << endl;
}
catch (CFileException cfileexcpt)
{
      cout << "here 4" << endl;
}
catch (CMemoryException cmemoryexcpt)
{
      cout << "here 5" << endl;
}
catch (CNotSupportedException cnotsupportedexcpt)
{
      cout << "here 6" << endl;
}
catch (COleDispatchException coledispatchexcpt)
{
      cout << "here 7" << endl;
}
catch (COleException coleexcpt)
{
      cout << "here 8" << endl;
}
catch (CResourceException cresourceexcpt)
{
      cout << "here 9" << endl;
}
catch (CUserException cuserexcpt)
{
      cout << "here 10" << endl;
}
catch (...)
{
      cout << "How did I get here??" << endl;
}


Somehow, the GetFieldValue line throws an exception. The documentation says it can only throw CDBException or CMemoryException. Why does my code get into the catch(...) block? What other exceptions could possibly be thrown?
jmnolanAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
chensuConnect With a Mentor Commented:
It seems that you have not learned from your previous question. Use a pointer.

try
{
//...
}
catch (CDBException *pe)
{
    pe->Delete();
}
catch (CMemoryException *pe)
{
    pe->Delete();
}
0
 
nietodCommented:
Why not use the debugger or RTTI to find out what sort of exception object you are catching?
0
 
jmnolanAuthor Commented:
I was stepping through with the debugger and the windows message box came up with the "Unhandled exception error..." message. Is there a way to tell what exception object was thrown? That would be very helpful..
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
arikkaCommented:
CRecordset::GetFieldValue method has throw specification attribute throw( CDBException, CMemoryException ), so this means that you as user know that this method may throw ONLY CDBException and CMemoryException exceptions.
I suppose that Microsoft uses their own compiler which according to Microsoft documentation :
"At this time the implementation details of exception specification have not been standardized,
and are accepted but not implemented in Microsoft Visual C++."

So, this throw exception specification may be ignored by compiler. Therefore, apparently
in this case throw exception is ignored and any exception may be thrown. You can't know exactly...

I took a look at samples provided by Microsoft, where they uses the next lines :

try{
...................
   var = rs.GetFieldValue(i);
...................
}
catch (CDaoException* e)
 {
      DisplayDaoException(e);
      e->Delete();
  return;
 }

arikka
0
 
jmnolanAuthor Commented:
I am using a CRecordset object, not a CDaoRecordset object. I am aware of the declaration of CRecordset::GetFieldValue which makes it confusiong because it doesn't throw either of the CDBException or CMemoryException exceptions. I need to be able to find out what exception was thrown.
0
 
chensuCommented:
It throws CDBException * instead of CDBException. Understand?
0
 
nietodCommented:
You said the exception is caught by catch (...) is that true?  Or is the exceptiuon never caught?  (you said you get the unhandled exception message, which indicates it is not caught.)
0
 
jmnolanAuthor Commented:
Damn pointers...

thanks again chensu!

nietod,
It is caught by catch(...), when I take that out I get the error message.

I'll never understand how you guys keep track of all these pointers.. Coming from the VB world, there are no pointers.

Thanks everyone!!
0
All Courses

From novice to tech pro — start learning today.