This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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: 2841
    
  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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: static method and exception
 
Similar Threads
Ejb Performance testing tool
ClassNotFoundException error
a question about "null"
File Class -Question
Ejb Performance testing tool