File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "static method and exception" Watch "static method and exception" New topic

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

throw new empty("Empty");
but it is only thorowing exception not deleting 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.

Greg Charles

Joined: Oct 01, 2001
Posts: 2968

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:
subject: static method and exception
It's not a secret anymore!