944,161 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 909
  • C++ RSS
Oct 26th, 2007
0

File not closing

Expand Post »
Hi all,
This is my problem:
C++ Syntax (Toggle Plain Text)
  1. void StartRun( void )
  2. {
  3. std::auto_ptr<Validate> val ( new Validate( "input.txt" ) );
  4. val->DoIt( );
  5. }
  6. // Destructor
  7. Validate::~WValidate( )
  8. {
  9. if( mFileIn.is_open())
  10. {
  11. mFileIn.close();
  12. }
  13. if( mFileOut.is_open() )
  14. {
  15. mFileOut.flush();
  16. mFileOut.close();
  17. }
  18. }

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.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
disc is offline Offline
29 posts
since Sep 2006
Oct 26th, 2007
0

Re: File not closing

Can you not catch all exceptions from DoIt ?
Reputation Points: 769
Solved Threads: 128
Banned
ithelp is offline Offline
1,910 posts
since May 2006
Oct 26th, 2007
0

Re: File not closing

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,963 posts
since Aug 2005
Oct 26th, 2007
0

Re: File not closing

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....
Reputation Points: 10
Solved Threads: 1
Light Poster
disc is offline Offline
29 posts
since Sep 2006
Oct 26th, 2007
0

Re: File not closing

Click to Expand / Collapse  Quote originally posted by disc ...
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.
Moderator
Reputation Points: 3281
Solved Threads: 896
Posting Sage
WaltP is offline Offline
7,749 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: one loop to perform 2 things
Next Thread in C++ Forum Timeline: Problem with static STL i.e. map





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC