Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Exception caught but not handled completely

Exception caught but not handled completely

Scheduled Pinned Locked Moved C / C++ / MFC
questiondatabasegraphicsdata-structuresdebugging
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Royce Fickling 0
    wrote on last edited by
    #1

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

    L 1 Reply Last reply
    0
    • R Royce Fickling 0

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

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      All the code in the exception handler should be able to execute outside the scope of the try block. One glaringly obvious potential you have is the use of pDataMovement pointer which is initialized in the try block. So if the exception is thrown before then or if the pointer is null your catch block will just throw another exception. Wait, looking again I see that pointer used before it is even declared so I don't know how you get that to compile at all.

      led mike

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups