@@ -10,6 +10,7 @@ module Control.Monad.Eff.Exception
1010 , catchException
1111 ) where
1212
13+ import Prelude
1314import Control.Monad.Eff (Eff ())
1415
1516-- | This effect is used to annotate code which possibly throws exceptions
@@ -21,28 +22,13 @@ foreign import data Error :: *
2122instance showError :: Show Error where
2223 show = showErrorImpl
2324
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
3026
3127-- | 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
3829
3930-- | 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
4632
4733-- | Throw an exception
4834-- |
@@ -54,14 +40,7 @@ foreign import message
5440-- | when (x < 0) $ throwException $
5541-- | error "Expected a non-negative number"
5642-- | ```
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
6544
6645-- | Catch an exception by providing an exception handler.
6746-- |
@@ -73,21 +52,4 @@ foreign import throwException
7352-- | main = catchException print do
7453-- | trace "Exceptions thrown in this block will be logged to the console"
7554-- | ```
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