I believe this should be

```scala
try f(writer)
finally writer.close()
```