module Prolude.Exception
  ( -- * Exception re-exports
    module Control.Exception.Safe
  , UnsafeException.AsyncException(..)
    -- * Exception functions
  , catchIf
  , unsafeEvaluate
  , unsafeThrow
  )
where

import Prolude.Core

import qualified Control.Exception as UnsafeException
import Control.Exception.Safe hiding (catchIO, throwM)

-- | Function alias for Control.Exception.evaluate
unsafeEvaluate :: a -> IO a
unsafeEvaluate :: a -> IO a
unsafeEvaluate = a -> IO a
forall a. a -> IO a
UnsafeException.evaluate

-- | Function alias for Control.Exception.throw
unsafeThrow :: Exception e => e -> a
unsafeThrow :: e -> a
unsafeThrow = e -> a
forall a e. Exception e => e -> a
UnsafeException.throw

-- | Catch exception based on a predicate
catchIf :: (MonadCatch m, Exception e) => (e -> Bool) -> m a -> (e -> m a) -> m a
catchIf :: (e -> Bool) -> m a -> (e -> m a) -> m a
catchIf e -> Bool
f m a
a e -> m a
b = m a -> (e -> m a) -> m a
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
m a -> (e -> m a) -> m a
catch m a
a ((e -> m a) -> m a) -> (e -> m a) -> m a
forall a b. (a -> b) -> a -> b
$ \e
e -> if e -> Bool
f e
e then e -> m a
b e
e else e -> m a
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throw e
e