Skip to content

rethrow: throw a new, modified version of an exception #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
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