954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

File not closing

Hi all,
This is my problem:

void StartRun( void )
{
    std::auto_ptr<Validate> val ( new Validate( "input.txt" ) );
    val->DoIt( );
}
// Destructor
Validate::~WValidate( )
{
  if( mFileIn.is_open())
  {
    mFileIn.close();
  }
  if( mFileOut.is_open() )
  {
    mFileOut.flush();
    mFileOut.close();
  }
}


The function DoIt() makes use of a DLL. Now heres the problem:
When there is an exception thrown by the DLL, I should say the
mFileOut should always be closed but it doesn't. I can't delete
the outputfile until I close my application because it says the
file is still open.
It only closes in the 'Debug Build' but not in the 'Release Build'.
Anyone has an idea ??
I use the Borland Developer Studio 2006.

disc
Light Poster
29 posts since Sep 2006
Reputation Points: 10
Solved Threads: 1
 

Can you not catch all exceptions from DoIt ?

ithelp
Nearly a Posting Maven
Banned
2,230 posts since May 2006
Reputation Points: 769
Solved Threads: 128
 

My guess is that your program is crashing sooooo bad that the destructor is not getting called, the program is just dumping back to the os without doing any cleanup. You really need to find out what is causing the exception and fix it. Lacking that you should implement exceptions (try/catch blocks) as ithelp suggested.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 
My guess is that your program is crashing sooooo bad that the destructor is not getting called, the program is just dumping back to the os without doing any cleanup. You really need to find out what is causing the exception and fix it. Lacking that you should implement exceptions (try/catch blocks) as ithelp suggested.



The try/catch block is already implemented in the DoIt function but that's not the solution because the exception is caused by a third party DLL.
It's still a fact that in the 'Debug Build' the destructor is called, and the file can be deleted, but in the 'Release Build' it isn't.
So suggestions are still welcome....

disc
Light Poster
29 posts since Sep 2006
Reputation Points: 10
Solved Threads: 1
 
The try/catch block is already implemented in the DoIt function but that's not the solution because the exception is caused by a third party DLL.


Talk to the third party. They have a better chance of figuring out what's going wrong.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You