Add a custom error handler that in the case of an error during closing simply logs the error and returns the result that was calculated before closing.
Illustrate how a default value can be returned if an error occurs.
Illustrate how a default value can be returned if an error occurs.
In the example below it is known that only a single request will be made, and the type of result is also known so a default value can be provided.
This pattern can be quite tricky because the internals of how Scala-IO works needs to be known. For example if providing a default for string then one must know that bytes must be returned as the default rather than a string.
Also if the scala-io implementation changes the code could break. Defaults work better when working with acquireAndGet or acquireFor
Illustrate an alternate (and advanced) pattern where in the case of an exception a default value is returned by the error handler.
Illustrate an alternate (and advanced) pattern where in the case of an exception a default value is returned by the error handler.
This is not a particularly common pattern of usage, but illustrates one of the more advanced possibilities
Examples of how to provide custom error handlers when using Scala IO.
By default a ScalaIOException is thrown when an error occurs accessing or closing a resource. The following examples illustrate how this default behaviour can be customized for a specific application.