withResource()
needs an implicit evidence parameter of this type
to know how to release what's passed to it.
withResource()
needs an implicit evidence parameter of this type
to know how to release what's passed to it.
the type (which must be contravariant to allow, for instance,
a T
of Closeable
to apply to subclasses like InputStream
).
Companion object for CanReleaseResource
.
A version of grizzled.util.withResource that captures any thrown exception, instead of propagating it.
A version of grizzled.util.withResource that captures any thrown exception, instead of propagating it.
the type of the resource
the return type of the code block
the by-name parameter (code block) to open the resource. This parameter is a by-name parameter so that this function can capture any exceptions it throws.
the code block to execute with the resource
the resource manager that can release the resource
A Success
containing the result of the code block, or a
Failure
with any thrown exception.
Ensure that a closeable object is closed.
Ensure that a closeable object is closed. Note that this function
requires an implicit evidence parameter of type CanClose
to determine
how to close the object. You can implement your own, though common
ones are provided automatically.
Sample use:
withResource(new java.io.FileInputStream("/path/to/file")) { in => ... }
Note: If the block throws an exception, withResource
propagates
the exception. If you want to capture the exception, instead, use
grizzled.util.tryWithResource.
the type of the resource
the return type of the code block
the object that holds a resource to be released
the code block to execute with the resource
the resource manager that can release the resource
whatever the block returns
Miscellaneous utility functions and methods not otherwise categorized.