File tree Expand file tree Collapse file tree 2 files changed +44
-7
lines changed
Expand file tree Collapse file tree 2 files changed +44
-7
lines changed Original file line number Diff line number Diff line change 44
55### Types
66
7- data Exception :: * -> !
7+ data Error :: *
8+
9+ data Exception :: !
10+
11+
12+ ### Type Class Instances
13+
14+ instance showError :: Show Error
815
916
1017### Values
1118
12- catchException :: forall e r a. (e -> Eff r a) -> Eff (err :: Exception e | r) a -> Eff r a
19+ catchException :: forall a eff. (Error -> Eff eff a) -> Eff (err :: Exception | eff) a -> Eff eff a
20+
21+ error :: String -> Error
22+
23+ message :: Error -> String
24+
25+ showErrorImpl :: Error -> String
1326
14- throwException :: forall a e r. e -> Eff (err :: Exception e | r ) a
27+ throwException :: forall a eff. Error -> Eff (err :: Exception | eff ) a
Original file line number Diff line number Diff line change @@ -2,14 +2,34 @@ module Control.Monad.Eff.Exception where
22
33import Control.Monad.Eff
44
5- foreign import data Exception :: * -> !
5+ foreign import data Exception :: !
66
7+ foreign import data Error :: *
8+
9+ instance showError :: Show Error where
10+ show = showErrorImpl
11+
12+ foreign import showErrorImpl
13+ " function showErrorImpl(err) {\
14+ \ return err.stack ? err.stack : err.toString();\
15+ \}" :: Error -> String
16+
17+ foreign import error
18+ " function error(msg) {\
19+ \ return new Error(msg);\
20+ \};" :: String -> Error
21+
22+ foreign import message
23+ " function message(e) {\
24+ \ return e.message;\
25+ \}" :: Error -> String
26+
727foreign import throwException
828 " function throwException(e) {\
929 \ return function() {\
1030 \ throw e;\
1131 \ };\
12- \}" :: forall a e r . e -> Eff (err :: Exception e | r ) a
32+ \}" :: forall a eff . Error -> Eff (err :: Exception | eff ) a
1333
1434foreign import catchException
1535 " function catchException(c) {\
@@ -18,8 +38,12 @@ foreign import catchException
1838 \ try {\
1939 \ return t();\
2040 \ } catch(e) {\
21- \ return c(e)();\
41+ \ if (e instanceof Error) {\
42+ \ return c(e)();\
43+ \ } else {\
44+ \ throw e;\
45+ \ }\
2246 \ }\
2347 \ };\
2448 \ };\
25- \}" :: forall e r a . (e -> Eff r a ) -> Eff (err :: Exception e | r ) a -> Eff r a
49+ \}" :: forall a eff . (Error -> Eff eff a ) -> Eff (err :: Exception | eff ) a -> Eff eff a
You can’t perform that action at this time.
0 commit comments