title: Using a variable in finally block
body: <p>Here is code in Scala:</p>
  
  <pre><code>def write() = {
      try {
        val out = new PrintWriter(new BufferedWriter(new FileWriter(fileName, true)))
        out.println("123")
        out.close
      } catch {
        case e: IOException =&gt; {}
      }
  
     //finally {
       //out.close // ops, it's not visible in this context
     //}
    }
  </code></pre>
  
  <p>It would be better to have "<code>out.close</code>" in <code>finally</code> block, isn't it? But I don't want to use var. </p>
  
  <p>My question is, how do I achieve that?</p>