Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Control/Monad/Eff/Exception.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ module Control.Monad.Eff.Exception
, stack
, throwException
, catchException
, rethrowException
, throw
, try
) where

import Prelude

import Control.Monad.Eff (Eff, kind Effect)
import Control.Monad.Eff.Unsafe (unsafeCoerceEff)

import Data.Either (Either(..))
import Data.Maybe (Maybe(..))
Expand Down Expand Up @@ -78,6 +80,11 @@ foreign import catchException
-> Eff (exception :: EXCEPTION | eff) a
-> Eff eff a

-- | If an exception is thrown, catch it and throw a new one.
rethrowException :: forall eff. (Error -> Error) -> Eff (exception :: EXCEPTION | eff) ~> Eff (exception :: EXCEPTION | eff)
rethrowException errFn =
catchException (throwException <<< errFn) <<< unsafeCoerceEff

-- | A shortcut allowing you to throw an error in one step. Defined as
-- | `throwException <<< error`.
throw :: forall eff a. String -> Eff (exception :: EXCEPTION | eff) a
Expand Down