Skip to content

Commit f927c62

Browse files
authored
Merge pull request #163 from akheron/issue-158
Update README.md
2 parents f6d95e9 + 22ffaa5 commit f927c62

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

README.md

+13-5
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@ synchronous code.
118118
## Dealing with Failure
119119

120120
`Aff` has error handling baked in, so ordinarily you don't have to worry
121-
about it.
121+
about it. For control-flow exceptions, it's advised to use `ExceptT`
122+
instead throwing errors in the `Aff` context. The support for errors
123+
mainly exists to notify you when very bad things happen.
122124

123-
When you need to deal with failure, you have a few options.
125+
However, when you need to deal with `Aff` errors, you have a few options.
124126

125127
1. **Alt**
126128
2. **MonadError**
@@ -139,15 +141,21 @@ example = do
139141

140142
#### 2. MonadError
141143

142-
`Aff` has a `MonadError` instance, which comes with two functions:
143-
`catchError`, and `throwError`.
144+
`Aff` has a `MonadError` instance, which comes with three functions:
145+
`try`, `catchError`, and `throwError`.
144146

145147
These are defined in
146148
[purescript-transformers](http://github.com/purescript/purescript-transformers).
147149
Here's an example of how you can use them:
148150

149151
```purescript
150-
example = do
152+
tryExample = do
153+
result <- try $ Ajax.get "http://foo.com"
154+
case result of
155+
Left err -> pure ""
156+
Right resp -> pure resp.body
157+
158+
catchThrowExample = do
151159
resp <- Ajax.get "http://foo.com" `catchError` \_ -> pure defaultResponse
152160
when (resp.statusCode /= 200) do
153161
throwError myErr

0 commit comments

Comments
 (0)