Re: CTime constructor - MFC exception handler??
"j.a. harriman" <jeffrey_no_spam_alias@nospam.nospam> ha scritto nel
messaggio news:3A47F005-C6F1-40AE-819E-4D183F007610@microsoft.com...
void myFunction(SQL_TIMESTAMP_STRUCT ts, CTime &ctime)
{
CTime temp(ts.year, ts.month, ts.day, etc.);
//if no exception, then set ctime
ctime = temp;
return;
}
The error it throws is:
Unhandled exception...Microsoft C++ exception: COleException at memory
location
I would like to know how I catch this in an exception handler.
I think that COleException is derived from CException, the base class for
MFC exceptions. My understanding is that in standard C++, exceptions are
caugth by reference, e.g.:
try
{
...
}
catch( StandardException & e ) // exception derived from std::exception
root
{
...
}
but in a MFC context, exceptions are managed using *pointers*, e.g.
try
{
...
}
catch ( CException * e )
{
// Handle the exception
e->Delete();
}
So, assuming that COleException is derived from CException, I think that you
should use the second option (i.e. catch by pointer).
I also recall that MFC has some macros to handle exceptions (something like
TRY...CATCH...), but I would think that using C++ standard keywords like
try/catch is better.
Moreover, IIRC Doug (C++ MVP, and C++ very expert) has a web site where he
discusses about MFC exceptions, how to try/catch them, and also he presents
a technique for catching both C++ "standard" exceptions and MFC exceptions -
very interesting article, but I've not the URL here.
Giovanni