File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes try / catch / finally Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "try / catch / finally" Watch "try / catch / finally" New topic

try / catch / finally

Ernie Mcracken
Ranch Hand

Joined: Feb 13, 2011
Posts: 33

Im trying to get my head around try / catch / finally blocks. I want to be able to use finally to close an input stream.. but I can't figure out the code i need to use. Heres what I have. How do I organise my code to get it right?

At compile time I get cannot find symbol: variale fr, I guess this means that I cannot access the fis object from the finally statement, but I don't know how to organise the code so that I can.

You're on a gravy train with biscuit wheels Roy.
Matthew Brown

Joined: Apr 06, 2010
Posts: 4544

You need to declare fis outside the block, so it can be accessed in both the try and finally blocks. Like this:
Ernie Mcracken
Ranch Hand

Joined: Feb 13, 2011
Posts: 33

That simple! thanks very much.
I agree. Here's the link:
subject: try / catch / finally
jQuery in Action, 3rd edition