943,641 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1026
  • C++ RSS
May 16th, 2009
0

do CopyFile() DeletFile() function throw exception?

Expand Post »
I use in my code (c++) CopyFile and DeleteFIle do these fumctions throw exceptions? do I need to surround them with try and catch?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dev565 is offline Offline
3 posts
since May 2009
May 16th, 2009
0

Re: do CopyFile() DeletFile() function throw exception?

I guess the best way to know is to test it!

Put a try block to catch all and enter an invalid file. See what happens?
Reputation Points: 673
Solved Threads: 125
Practically a Posting Shark
Sky Diploma is offline Offline
818 posts
since Mar 2008
May 16th, 2009
0

Re: do CopyFile() DeletFile() function throw exception?

You could use the File::Exists to first check if that file exists and then it will not through an exception.

C++ Syntax (Toggle Plain Text)
  1. String^ FileOne = "C:\\File1.txt";
  2. String^ FileTwo = "C:\\File2.txt";
  3.  
  4. if( File::Exists(FileOne)
  5. {
  6. File::Copy(FileOne, FileTwo);
  7. }


or

C++ Syntax (Toggle Plain Text)
  1. String^ FileOne = "C:\\File1.txt";
  2. String^ FileTwo = "C:\\File2.txt";
  3.  
  4. if( File::Exists(FileOne)
  5. {
  6. try
  7. {
  8. File::Copy(FileOne, FileTwo);
  9. }
  10. catch(Exception^ Ex )
  11. {
  12. MessageBox::Show("Something is wrong");
  13. }
  14. }
Last edited by Liszt; May 16th, 2009 at 3:54 pm.
Reputation Points: 33
Solved Threads: 6
Junior Poster
Liszt is offline Offline
122 posts
since Oct 2008

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: dynamic stack using vector strategy
Next Thread in C++ Forum Timeline: Ways to get a Computers "ID"





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


Follow us on Twitter


© 2011 DaniWeb® LLC