1
1
-- | This module defines an effect, actions and handlers for working
2
2
-- | with JavaScript exceptions.
3
3
4
- module Control.Monad.Eff.Exception
5
- ( EXCEPTION
6
- , Error
4
+ module Control.Monad.Effect.Exception
5
+ ( Error
7
6
, error
8
7
, message
9
8
, name
@@ -16,14 +15,11 @@ module Control.Monad.Eff.Exception
16
15
17
16
import Prelude
18
17
19
- import Control.Monad.Eff ( Eff , kind Effect )
18
+ import Control.Monad.Effect ( Effect )
20
19
21
20
import Data.Either (Either (..))
22
21
import Data.Maybe (Maybe (..))
23
22
24
- -- | This effect is used to annotate code which possibly throws exceptions
25
- foreign import data EXCEPTION :: Effect
26
-
27
23
-- | The type of JavaScript errors
28
24
foreign import data Error :: Type
29
25
@@ -62,29 +58,27 @@ foreign import stackImpl
62
58
-- | error "Expected a non-negative number"
63
59
-- | ```
64
60
foreign import throwException
65
- :: forall a eff
61
+ :: forall a
66
62
. Error
67
- -> Eff ( exception :: EXCEPTION | eff ) a
63
+ -> Effect a
68
64
69
65
-- | Catch an exception by providing an exception handler.
70
66
-- |
71
- -- | This handler removes the `EXCEPTION` effect.
72
- -- |
73
67
-- | For example:
74
68
-- |
75
69
-- | ```purescript
76
70
-- | main = catchException print do
77
71
-- | Console.log "Exceptions thrown in this block will be logged to the console"
78
72
-- | ```
79
73
foreign import catchException
80
- :: forall a eff
81
- . (Error -> Eff eff a )
82
- -> Eff ( exception :: EXCEPTION | eff ) a
83
- -> Eff eff a
74
+ :: forall a
75
+ . (Error -> Effect a )
76
+ -> Effect a
77
+ -> Effect a
84
78
85
79
-- | A shortcut allowing you to throw an error in one step. Defined as
86
80
-- | `throwException <<< error`.
87
- throw :: forall eff a . String -> Eff ( exception :: EXCEPTION | eff ) a
81
+ throw :: forall a . String -> Effect a
88
82
throw = throwException <<< error
89
83
90
84
-- | Runs an Eff and returns eventual Exceptions as a `Left` value. If the
@@ -93,8 +87,7 @@ throw = throwException <<< error
93
87
-- | For example:
94
88
-- |
95
89
-- | ```purescript
96
- -- | -- Notice that there is no EXCEPTION effect
97
- -- | main :: forall eff. Eff (console :: CONSOLE, fs :: FS | eff) Unit
90
+ -- | main :: forall eff. Effect Unit
98
91
-- | main = do
99
92
-- | result <- try (readTextFile UTF8 "README.md")
100
93
-- | case result of
@@ -104,5 +97,5 @@ throw = throwException <<< error
104
97
-- | Console.error ("Couldn't open README.md. Error was: " <> show error)
105
98
-- | ```
106
99
107
- try :: forall eff a . Eff ( exception :: EXCEPTION | eff ) a -> Eff eff (Either Error a )
100
+ try :: forall a . Effect a -> Effect (Either Error a )
108
101
try action = catchException (pure <<< Left ) (Right <$> action)
0 commit comments