module Prolude.Exception
  ( module Control.Exception.Safe
  , UnsafeException.AsyncException(..)
  , catchIf
  , unsafeEvaluate
  , unsafeThrow
  )
where

import Prolude.Core

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

unsafeEvaluate :: a -> IO a
unsafeEvaluate :: a -> IO a
unsafeEvaluate = a -> IO a
forall a. a -> IO a
UnsafeException.evaluate

unsafeThrow :: Exception e => e -> a
unsafeThrow :: e -> a
unsafeThrow = e -> a
forall a e. Exception e => e -> a
UnsafeException.throw

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