File not closing

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2006
Posts: 22
Reputation: disc is an unknown quantity at this point 
Solved Threads: 1
disc disc is offline Offline
Newbie Poster

File not closing

 
0
  #1
Oct 26th, 2007
Hi all,
This is my problem:
  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.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,857
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 120
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso

Re: File not closing

 
0
  #2
Oct 26th, 2007
Can you not catch all exceptions from DoIt ?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,585
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1487
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: File not closing

 
0
  #3
Oct 26th, 2007
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 22
Reputation: disc is an unknown quantity at this point 
Solved Threads: 1
disc disc is offline Offline
Newbie Poster

Re: File not closing

 
0
  #4
Oct 26th, 2007
Originally Posted by Ancient Dragon View Post
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....
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,117
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 282
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: File not closing

 
0
  #5
Oct 26th, 2007
Originally Posted by disc View Post
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.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC