Thread: Copying a File
View Single Post
Old 10-26-2012, 09:21 PM   PM User | #15
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Doing this is completely pointless:
Code:
				try{
					throw new FileNameException();
				}catch (FileNameException e){
					e.printStackTrace();
				}
This is simply manually triggering an exception and being caught in the same block. It serves no purpose. The only time you should bother throwing an exception within a try manually is if its to force the remaining code to not execute. That is easily done in an if branch though.

Exceptions should be used for when you do not know if if a condition may be raised, but could possibly be raised. You can throw your own exceptions, but you should be handling them in the caller if this is the case. Exceptions are raised by a block of code since they don't know what else to do with them. They leave it up to whatever called the method to determine how to proceed.

IMO every one of these conditions above are valid. The only possible exception is sourceFileName.txt to sourceFileName.doc, and that is still debatable. The extension itself means nothing on the data within the file, so I don't see an issue with that. I'm not sure why you have a condition like this: if(srcFileName != "sourceFileName.txt" || dstFileName != "destinationFileName.txt"). Don't forget the rules of strings as well; use .equals for comparisons of immutable types, not == and !=. But these rules overall say you must use suorceFileName.txt and destinationFileName.txt, so what is the point of having the arguments provide to the java command line?
Fou-Lu is offline   Reply With Quote