Starts a loan(resource) to { ... }
statement.
Starts a loan(resource) to { ... }
statement.
Usage example:
loan(new PrintWriter(new FileOutputStream("hello-world.txt"))) to { w: PrintWriter => w.println("Hello world!") }
In this example, w.close()
is guaranteed to get called even if the to-function terminates with a Throwable.
In general, if the to-function throws a throwable t1
and the AutoCloseable.close()
method throws another
throwable t2
, then the throwable t2
gets added to the throwable t1
using t1.addSuppressed(t2)
.
the type of the auto-closeable resource.
the auto-closeable resource.
A mix-in trait which provides resource functions.