File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 Murach's Java Servlets and JSP this week in the Servlets 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: 2833
    
  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.
 
Don't get me started about those stupid light bulbs.
 
subject: static method and exception
 
Similar Threads
Ejb Performance testing tool
a question about "null"
File Class -Question
Ejb Performance testing tool
ClassNotFoundException error