(original) (raw)
{-# LANGUAGE Trustworthy #-} {-# LANGUAGE NoImplicitPrelude, ExistentialQuantification #-}
module Control.Exception (
[SomeException](GHC.Exception.Type.html#SomeException)(..),
[Exception](GHC.Exception.Type.html#Exception)(..),
[IOException](GHC.IO.Exception.html#IOException),
[ArithException](GHC.Exception.Type.html#ArithException)(..),
[ArrayException](GHC.IO.Exception.html#ArrayException)(..),
[AssertionFailed](GHC.IO.Exception.html#AssertionFailed)(..),
[SomeAsyncException](GHC.IO.Exception.html#SomeAsyncException)(..),
[AsyncException](GHC.IO.Exception.html#AsyncException)(..),
[asyncExceptionToException](GHC.IO.Exception.html#asyncExceptionToException), [asyncExceptionFromException](GHC.IO.Exception.html#asyncExceptionFromException),
[NonTermination](Control.Exception.Base.html#NonTermination)(..),
[NestedAtomically](Control.Exception.Base.html#NestedAtomically)(..),
[BlockedIndefinitelyOnMVar](GHC.IO.Exception.html#BlockedIndefinitelyOnMVar)(..),
[BlockedIndefinitelyOnSTM](GHC.IO.Exception.html#BlockedIndefinitelyOnSTM)(..),
[AllocationLimitExceeded](GHC.IO.Exception.html#AllocationLimitExceeded)(..),
[CompactionFailed](GHC.IO.Exception.html#CompactionFailed)(..),
[Deadlock](GHC.IO.Exception.html#Deadlock)(..),
[NoMethodError](Control.Exception.Base.html#NoMethodError)(..),
[PatternMatchFail](Control.Exception.Base.html#PatternMatchFail)(..),
[RecConError](Control.Exception.Base.html#RecConError)(..),
[RecSelError](Control.Exception.Base.html#RecSelError)(..),
[RecUpdError](Control.Exception.Base.html#RecUpdError)(..),
[ErrorCall](GHC.Exception.html#ErrorCall)(..),
[TypeError](Control.Exception.Base.html#TypeError)(..),
[throw](GHC.Exception.html#throw),
[throwIO](GHC.IO.html#throwIO),
[ioError](GHC.IO.Exception.html#ioError),
[throwTo](GHC.Conc.Sync.html#throwTo),
[catch](GHC.IO.html#catch),
[catches](Control.Exception.html#catches), [Handler](Control.Exception.html#Handler)(..),
[catchJust](Control.Exception.Base.html#catchJust),
[handle](Control.Exception.Base.html#handle),
[handleJust](Control.Exception.Base.html#handleJust),
[try](Control.Exception.Base.html#try),
[tryJust](Control.Exception.Base.html#tryJust),
[evaluate](GHC.IO.html#evaluate),
[mapException](Control.Exception.Base.html#mapException),
[mask](GHC.IO.html#mask),
[mask_](GHC.IO.html#mask%5F),
[uninterruptibleMask](GHC.IO.html#uninterruptibleMask),
[uninterruptibleMask_](GHC.IO.html#uninterruptibleMask%5F),
[MaskingState](GHC.IO.html#MaskingState)(..),
[getMaskingState](GHC.IO.html#getMaskingState),
[interruptible](GHC.IO.html#interruptible),
[allowInterrupt](Control.Exception.html#allowInterrupt),
[assert](GHC.Base.html#assert),
[bracket](Control.Exception.Base.html#bracket),
[bracket_](Control.Exception.Base.html#bracket%5F),
[bracketOnError](Control.Exception.Base.html#bracketOnError),
[finally](Control.Exception.Base.html#finally),
[onException](Control.Exception.Base.html#onException),) where
import Control.Exception.Base
import GHC.Base import GHC.IO (interruptible)
data Handler a = forall e . Exception e => Handler (e -> IO a)
instance Functor Handler where fmap :: forall a b. (a -> b) -> Handler a -> Handler b fmap a -> b f (Handler e -> IO a h) = (e -> IO b) -> Handler b forall a e. Exception e => (e -> IO a) -> Handler a Handler ((a -> b) -> IO a -> IO b forall a b. (a -> b) -> IO a -> IO b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap a -> b f (IO a -> IO b) -> (e -> IO a) -> e -> IO b forall b c a. (b -> c) -> (a -> b) -> a -> c . e -> IO a h)
catches :: IO a -> [Handler a] -> IO a
catches :: forall a. IO a -> [Handler a] -> IO a
catches IO a
io [Handler a]
handlers = IO a
io IO a -> (SomeException -> IO a) -> IO a
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
catch [Handler a] -> SomeException -> IO a
forall a. [Handler a] -> SomeException -> IO a
catchesHandler [Handler a]
handlers
catchesHandler :: [Handler a] -> SomeException -> IO a catchesHandler :: forall a. [Handler a] -> SomeException -> IO a catchesHandler [Handler a] handlers SomeException e = (Handler a -> IO a -> IO a) -> IO a -> [Handler a] -> IO a forall a b. (a -> b -> b) -> b -> [a] -> b foldr Handler a -> IO a -> IO a forall {a}. Handler a -> IO a -> IO a tryHandler (SomeException -> IO a forall a e. Exception e => e -> a throw SomeException e) [Handler a] handlers where tryHandler :: Handler a -> IO a -> IO a tryHandler (Handler e -> IO a handler) IO a res = case SomeException -> Maybe e forall e. Exception e => SomeException -> Maybe e fromException SomeException e of Just e e' -> e -> IO a handler e e' Maybe e Nothing -> IO a res
allowInterrupt :: IO () allowInterrupt :: IO () allowInterrupt = IO () -> IO () forall a. IO a -> IO a interruptible (IO () -> IO ()) -> IO () -> IO () forall a b. (a -> b) -> a -> b $ () -> IO () forall a. a -> IO a forall (m :: * -> *) a. Monad m => a -> m a return ()