title: Try-with-resources in Kotlin
body: <p>When I tried to write an equivalent of a Java <a href="https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html" rel="noreferrer"><code>try</code>-with-resources</a> statement in Kotlin, it didn't work for me.</p>
  <p>I tried different variations of the following:</p>
  <pre><code>try (writer = OutputStreamWriter(r.getOutputStream())) {
      // ...
  }
  </code></pre>
  <p>But neither works. Does anyone know what should be used instead?</p>
  <p>Apparently Kotlin grammar <a href="http://kotlinlang.org/docs/reference/grammar.html" rel="noreferrer">doesn't include</a> such a construct, but maybe I'm missing something. It defines the grammar for a <code>try</code> block as follows:</p>
  <pre><code>try : &quot;try&quot; block catchBlock* finallyBlock?;
  </code></pre>