Skip to content

Commit 3a7e328

Browse files
author
Alejandro Gómez
committed
Reword the description of error syntax
1 parent a318f5c commit 3a7e328

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

docs/src/tut/docs.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,10 +615,17 @@ val result: Int = Fetch.run[Eval](fetchPure).value
615615
### error
616616

617617
Errors 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
621625
val 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

0 commit comments

Comments
 (0)