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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

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 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.