Skip to content

Commit 8b01078

Browse files
committed
Add note about exceptions thrown in other threads
1 parent e4c8dcd commit 8b01078

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

docs/Control.Monad.Aff.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ launchAff :: forall e a. Aff e a -> Eff (err :: EXCEPTION | e) Unit
8585
Converts the asynchronous computation into a synchronous one. All values
8686
are ignored, and if the computation produces an error, it is thrown.
8787

88+
Catching exceptions by using `catchException` with the resulting Eff
89+
computation is not recommended, as exceptions may end up being thrown in
90+
a different thread, due to the asynchronous nature of Aff. In such a
91+
case, the exception cannot be caught.
92+
93+
If you do need to handle exceptions, you can use `runAff` instead, or
94+
you can handle the exception within the Aff computation, using
95+
`catchError` (or any of the other mechanisms).
96+
8897
#### `runAff`
8998

9099
``` purescript

src/Control/Monad/Aff.purs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ module Control.Monad.Aff
6666

6767
-- | Converts the asynchronous computation into a synchronous one. All values
6868
-- | are ignored, and if the computation produces an error, it is thrown.
69+
-- |
70+
-- | Catching exceptions by using `catchException` with the resulting Eff
71+
-- | computation is not recommended, as exceptions may end up being thrown in
72+
-- | a different thread, due to the asynchronous nature of Aff. In such a
73+
-- | case, the exception cannot be caught.
74+
-- |
75+
-- | If you do need to handle exceptions, you can use `runAff` instead, or
76+
-- | you can handle the exception within the Aff computation, using
77+
-- | `catchError` (or any of the other mechanisms).
6978
launchAff :: forall e a. Aff e a -> Eff (err :: EXCEPTION | e) Unit
7079
launchAff = runAff throwException (const (pure unit)) <<< liftEx
7180
where

0 commit comments

Comments
 (0)