• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

try / catch / finally

 
Ernie Mcracken
Ranch Hand
Posts: 33
Mac Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
Mac Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That simple! thanks very much.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic