File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -615,10 +615,17 @@ val result: Int = Fetch.run[Eval](fetchPure).value
615615### error
616616
617617Errors can also be lifted to the Fetch monad, in this case with ` Fetch#error ` . Note that interpreting
618- an errorful fetch to ` Eval ` will throw the exception so we won't do that:
618+ an errorful fetch to ` Eval ` won't throw the exception unless we access the value with the ` .value ` method.
619+
620+ A safer way to deal with errors is to use MonadError's ` attempt ` to turn the exception into a ` Xor.Left ` value:
621+
622+ ``` tut:book
623+ val ME = implicitly[MonadError[Eval, Throwable]]
619624
620- ``` tut:silent
621625val fetchFail: Fetch[Int] = Fetch.error(new Exception("Something went terribly wrong"))
626+ val result: Eval[Int] = fetchFail.runA[Eval]
627+ val safeResult: Eval[Throwable Xor Int] = ME.attempt(result)
628+ val finalValue: Throwable Xor Int = safeResult.value
622629```
623630
624631### join
You can’t perform that action at this time.
0 commit comments