Skip to content

Commit 6789792

Browse files
committed
Use Error type for exceptions
1 parent d6cfde8 commit 6789792

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
### Types
66

7-
data Exception :: * -> !
7+
type Error = { stack :: String, message :: String }
8+
9+
data Exception :: !
810

911

1012
### Values
1113

12-
catchException :: forall e r a. (e -> Eff r a) -> Eff (err :: Exception e | r) a -> Eff r a
14+
catchException :: forall a eff. (Error -> Eff eff a) -> Eff (err :: Exception | eff) a -> Eff eff a
1315

14-
throwException :: forall a e r. e -> Eff (err :: Exception e | r) a
16+
throwException :: forall a eff. Error -> Eff (err :: Exception | eff) a

src/Control/Monad/Eff/Exception.purs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ module Control.Monad.Eff.Exception where
22

33
import Control.Monad.Eff
44

5-
foreign import data Exception :: * -> !
5+
foreign import data Exception :: !
6+
7+
type Error = { message :: String, stack :: String }
68

79
foreign import throwException
810
"function throwException(e) {\
911
\ return function() {\
1012
\ throw e;\
1113
\ };\
12-
\}" :: forall a e r. e -> Eff (err :: Exception e | r) a
14+
\}" :: forall a eff. Error -> Eff (err :: Exception | eff) a
1315

1416
foreign import catchException
1517
"function catchException(c) {\
@@ -18,8 +20,12 @@ foreign import catchException
1820
\ try {\
1921
\ return t();\
2022
\ } catch(e) {\
21-
\ return c(e)();\
23+
\ if (e instanceof Error) {\
24+
\ return c(e)();\
25+
\ } else {\
26+
\ throw e;\
27+
\ }\
2228
\ }\
2329
\ };\
2430
\ };\
25-
\}" :: forall e r a. (e -> Eff r a) -> Eff (err :: Exception e | r) a -> Eff r a
31+
\}" :: forall a eff. (Error -> Eff eff a) -> Eff (err :: Exception | eff) a -> Eff eff a

0 commit comments

Comments
 (0)