do CopyFile() DeletFile() function throw exception?

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

Join Date: May 2009
Posts: 3
Reputation: dev565 is an unknown quantity at this point 
Solved Threads: 0
dev565 dev565 is offline Offline
Newbie Poster

do CopyFile() DeletFile() function throw exception?

 
0
  #1
May 16th, 2009
I use in my code (c++) CopyFile and DeleteFIle do these fumctions throw exceptions? do I need to surround them with try and catch?
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 678
Reputation: Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold 
Solved Threads: 101
Sky Diploma's Avatar
Sky Diploma Sky Diploma is offline Offline
Practically a Master Poster

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

 
0
  #2
May 16th, 2009
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?
1. Please Mark Your Thread as Solved After Getting Your Answers.
2. Please Use CODE TAGS .
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 122
Reputation: Liszt is an unknown quantity at this point 
Solved Threads: 6
Liszt Liszt is offline Offline
Junior Poster

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

 
0
  #3
May 16th, 2009
You could use the File::Exists to first check if that file exists and then it will not through an exception.

  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

  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.
Reply With Quote Quick reply to this message  
Reply

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




Views: 448 | Replies: 2
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC