@@ -10,6 +10,7 @@ module Control.Monad.Eff.Exception
10
10
, catchException
11
11
) where
12
12
13
+ import Prelude
13
14
import Control.Monad.Eff (Eff ())
14
15
15
16
-- | This effect is used to annotate code which possibly throws exceptions
@@ -21,28 +22,13 @@ foreign import data Error :: *
21
22
instance showError :: Show Error where
22
23
show = showErrorImpl
23
24
24
- foreign import showErrorImpl
25
- " " "
26
- function showErrorImpl(err) {
27
- return err.stack || err.toString();
28
- }
29
- " " " :: Error -> String
25
+ foreign import showErrorImpl :: Error -> String
30
26
31
27
-- | Create a Javascript error, specifying a message
32
- foreign import error
33
- " " "
34
- function error(msg) {
35
- return new Error(msg);
36
- }
37
- " " " :: String -> Error
28
+ foreign import error :: String -> Error
38
29
39
30
-- | Get the error message from a Javascript error
40
- foreign import message
41
- " " "
42
- function message(e) {
43
- return e.message;
44
- }
45
- " " " :: Error -> String
31
+ foreign import message :: Error -> String
46
32
47
33
-- | Throw an exception
48
34
-- |
@@ -54,14 +40,7 @@ foreign import message
54
40
-- | when (x < 0) $ throwException $
55
41
-- | error "Expected a non-negative number"
56
42
-- | ```
57
- foreign import throwException
58
- " " "
59
- function throwException(e) {
60
- return function() {
61
- throw e;
62
- };
63
- }
64
- " " " :: forall a eff . Error -> Eff (err :: EXCEPTION | eff ) a
43
+ foreign import throwException :: forall a eff . Error -> Eff (err :: EXCEPTION | eff ) a
65
44
66
45
-- | Catch an exception by providing an exception handler.
67
46
-- |
@@ -73,21 +52,4 @@ foreign import throwException
73
52
-- | main = catchException print do
74
53
-- | trace "Exceptions thrown in this block will be logged to the console"
75
54
-- | ```
76
- foreign import catchException
77
- " " "
78
- function catchException(c) {
79
- return function(t) {
80
- return function() {
81
- try {
82
- return t();
83
- } catch(e) {
84
- if (e instanceof Error || Object.prototype.toString.call(e) === '[object Error]') {
85
- return c(e)();
86
- } else {
87
- return c(new Error(e.toString()))();
88
- }
89
- }
90
- };
91
- };
92
- }
93
- " " " :: forall a eff . (Error -> Eff eff a ) -> Eff (err :: EXCEPTION | eff ) a -> Eff eff a
55
+ foreign import catchException :: forall a eff . (Error -> Eff eff a ) -> Eff (err :: EXCEPTION | eff ) a -> Eff eff a
0 commit comments