aspose file tools*
The moose likes Java in General and the fly likes static method and exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "static method and exception" Watch "static method and exception" New topic
Author

static method and exception

arjun rampal
Ranch Hand

Joined: Jul 08, 2005
Posts: 125
I have file which is reading from file and deleting it.
delete is done by static method.
now i need to do like this if file is empty it should throw exception and delte the file.
so i added else like this
else{

throw new empty("Empty");
}
but it is only thorowing exception not deleting file.as that static code is unreachable after throwing exception.
any idea
John Kelty
Ranch Hand

Joined: Aug 08, 2006
Posts: 33
If I understand right, you want to delete the file whether or not you throw an exception. Try placing the file delete logic in a finally {} block.

--John
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2864
    
  11

Or, find out if the file is empty and save that into a boolean variable. Then delete the file, then take any action based on the boolean that you think is appopriate.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static method and exception