11-- | This module defines an effect, actions and handlers for working
22-- | with JavaScript exceptions.
33
4- module Control.Monad.Eff.Exception
5- ( EXCEPTION
6- , Error
4+ module Control.Monad.Effect.Exception
5+ ( Error
76 , error
87 , message
98 , name
@@ -16,14 +15,11 @@ module Control.Monad.Eff.Exception
1615
1716import Prelude
1817
19- import Control.Monad.Eff ( Eff , kind Effect )
18+ import Control.Monad.Effect ( Effect )
2019
2120import Data.Either (Either (..))
2221import Data.Maybe (Maybe (..))
2322
24- -- | This effect is used to annotate code which possibly throws exceptions
25- foreign import data EXCEPTION :: Effect
26-
2723-- | The type of JavaScript errors
2824foreign import data Error :: Type
2925
@@ -62,29 +58,27 @@ foreign import stackImpl
6258-- | error "Expected a non-negative number"
6359-- | ```
6460foreign import throwException
65- :: forall a eff
61+ :: forall a
6662 . Error
67- -> Eff ( exception :: EXCEPTION | eff ) a
63+ -> Effect a
6864
6965-- | Catch an exception by providing an exception handler.
7066-- |
71- -- | This handler removes the `EXCEPTION` effect.
72- -- |
7367-- | For example:
7468-- |
7569-- | ```purescript
7670-- | main = catchException print do
7771-- | Console.log "Exceptions thrown in this block will be logged to the console"
7872-- | ```
7973foreign 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
8478
8579-- | A shortcut allowing you to throw an error in one step. Defined as
8680-- | `throwException <<< error`.
87- throw :: forall eff a . String -> Eff ( exception :: EXCEPTION | eff ) a
81+ throw :: forall a . String -> Effect a
8882throw = throwException <<< error
8983
9084-- | Runs an Eff and returns eventual Exceptions as a `Left` value. If the
@@ -93,8 +87,7 @@ throw = throwException <<< error
9387-- | For example:
9488-- |
9589-- | ```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
9891-- | main = do
9992-- | result <- try (readTextFile UTF8 "README.md")
10093-- | case result of
@@ -104,5 +97,5 @@ throw = throwException <<< error
10497-- | Console.error ("Couldn't open README.md. Error was: " <> show error)
10598-- | ```
10699
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 )
108101try action = catchException (pure <<< Left ) (Right <$> action)
0 commit comments