RoyceF
May 20th, 2008, 03:20 PM
I have an exception handling problem that I don't understand. My thread function is throwing an unhandled exception which is being caught by my catch(...) handler but not completely handled. This causes my thread to be prematurely terminated so that my cleanup logic is not executed. How can I change my handler so as to completely handle the exception and execute my cleanup logic? My code is below.
UINT CVarFileEvent::MultiFileProcessThread( LPVOID lpParam )
{
// This is the threaded multi-file processor. It
// searches for and processes all VAR files in the
// Inbox or until it is cancelled by a call from
// DataMovement due to a Cancel message from PC-GBS.
CVarFileEvent* pEvent = (CVarFileEvent*)lpParam;
TRACE( "> > > > Entering CVarFileEvent::MultiFileProcessThread()\n" );
// We must call ::CoInitialize() each time the database is accessed
HRESULT hRes = ::CoInitialize(NULL);
try
{
vector<CString> vecVarFiles = UtilK::findAllFiles( "*.var",
pDataMovement->getInboxPath(),
false );
TRACE( "> > > > > Beginning processing of %d VAR files\n",
(int)vecVarFiles.size() );
CDataMovement* pDataMovement = pEvent->getDataMovementParent();
CFlightDataHandler FlightDataHandler( pDataMovement->getLogWriter() );
// run until we are cancelled or all files processed
for( vector<CString>::iterator iterFile = vecVarFiles.begin();
iterFile != vecVarFiles.end() && m_bIsThreadRunning;
iterFile++ )
{
FlightDataHandler.importVARFile( *iterFile );
// now delete the input file and remove the event
// for this file from the queue if it exists
::DeleteFile( *iterFile );
pDataMovement->deleteFileEvent( *iterFile );
}
}
catch(...)
{
CString strMsg( "importVARFile() failed with unexpected exception" );
TRACE( "> > > > CVarFileEvent::MultiFileProcessThread() exception < %s >\n", strMsg );
CLogWriter* pLogWriter = pDataMovement->getLogWriter();
pLogWriter->writeEntry( "CVarFileEvent", CLogWriter::LE_OPERATION_FAILED, strMsg );
}
// Cleanup
::CoUninitialize();
// the main thread is waiting so indicate we have stopped processing
pDataMovement->setInboxProcessEndEvent();
m_bIsThreadRunning = false;
return 1;
}
Thanks
UINT CVarFileEvent::MultiFileProcessThread( LPVOID lpParam )
{
// This is the threaded multi-file processor. It
// searches for and processes all VAR files in the
// Inbox or until it is cancelled by a call from
// DataMovement due to a Cancel message from PC-GBS.
CVarFileEvent* pEvent = (CVarFileEvent*)lpParam;
TRACE( "> > > > Entering CVarFileEvent::MultiFileProcessThread()\n" );
// We must call ::CoInitialize() each time the database is accessed
HRESULT hRes = ::CoInitialize(NULL);
try
{
vector<CString> vecVarFiles = UtilK::findAllFiles( "*.var",
pDataMovement->getInboxPath(),
false );
TRACE( "> > > > > Beginning processing of %d VAR files\n",
(int)vecVarFiles.size() );
CDataMovement* pDataMovement = pEvent->getDataMovementParent();
CFlightDataHandler FlightDataHandler( pDataMovement->getLogWriter() );
// run until we are cancelled or all files processed
for( vector<CString>::iterator iterFile = vecVarFiles.begin();
iterFile != vecVarFiles.end() && m_bIsThreadRunning;
iterFile++ )
{
FlightDataHandler.importVARFile( *iterFile );
// now delete the input file and remove the event
// for this file from the queue if it exists
::DeleteFile( *iterFile );
pDataMovement->deleteFileEvent( *iterFile );
}
}
catch(...)
{
CString strMsg( "importVARFile() failed with unexpected exception" );
TRACE( "> > > > CVarFileEvent::MultiFileProcessThread() exception < %s >\n", strMsg );
CLogWriter* pLogWriter = pDataMovement->getLogWriter();
pLogWriter->writeEntry( "CVarFileEvent", CLogWriter::LE_OPERATION_FAILED, strMsg );
}
// Cleanup
::CoUninitialize();
// the main thread is waiting so indicate we have stopped processing
pDataMovement->setInboxProcessEndEvent();
m_bIsThreadRunning = false;
return 1;
}
Thanks