Commit 4b18de03 authored by Sven Tennie's avatar Sven Tennie 😺
Browse files

Replace SomeException with SomeExceptionWithBacktrace (#18159)

parent ebc21bd7
......@@ -74,10 +74,15 @@ module Control.Monad.Catch (
, bracketOnError
-- * Re-exports from Control.Exception
, Exception(..)
, SomeException(..)
, SomeExceptionWithBacktrace(..)
) where
import Control.Exception (Exception(..), SomeException(..))
import Control.Exception (Exception(..))
#if __GLASGOW_HASKELL__ >= 903
import Control.Exception (SomeExceptionWithBacktrace(..))
#else
import Control.Exception (SomeException(..))
#endif
import qualified Control.Exception as ControlException
import qualified Control.Monad.STM as STM
import qualified Control.Monad.Trans.RWS.Lazy as LazyRWS
......@@ -118,6 +123,10 @@ import Data.Monoid
import Control.Applicative
#endif
#if __GLASGOW_HASKELL__ < 903
type SomeExceptionWithBacktrace = SomeException
#endif
------------------------------------------------------------------------------
-- $mtl
-- The mtl style typeclass
......@@ -316,7 +325,7 @@ class MonadCatch m => MonadMask m where
-- ('ExitCaseAbort').
data ExitCase a
= ExitCaseSuccess a
| ExitCaseException SomeException
| ExitCaseException SomeExceptionWithBacktrace
| ExitCaseAbort
deriving Show
......@@ -350,17 +359,17 @@ instance MonadThrow STM where
instance MonadCatch STM where
catch = STM.catchSTM
instance e ~ SomeException => MonadThrow (Either e) where
instance e ~ SomeExceptionWithBacktrace => MonadThrow (Either e) where
throwM = Left . toException
-- | @since 0.8.3
instance e ~ SomeException => MonadCatch (Either e) where
instance e ~ SomeExceptionWithBacktrace => MonadCatch (Either e) where
catch (Left e) f =
case fromException e of
Nothing -> Left e
Just e' -> f e'
catch x@(Right _) _ = x
-- | @since 0.8.3
instance e ~ SomeException => MonadMask (Either e) where
instance e ~ SomeExceptionWithBacktrace => MonadMask (Either e) where
mask f = f id
uninterruptibleMask f = f id
......@@ -740,7 +749,7 @@ uninterruptibleMask_ io = uninterruptibleMask $ \_ -> io
--
-- /NOTE/ This catches all /exceptions/, but if the monad supports other ways of
-- aborting the computation, those other kinds of errors will not be caught.
catchAll :: MonadCatch m => m a -> (SomeException -> m a) -> m a
catchAll :: MonadCatch m => m a -> (SomeExceptionWithBacktrace -> m a) -> m a
catchAll = catch
-- | Catch all 'IOError' (eqv. 'IOException') exceptions. Still somewhat too
......@@ -771,7 +780,7 @@ handleIOError :: MonadCatch m => (IOError -> m a) -> m a -> m a
handleIOError = handle
-- | Flipped 'catchAll'
handleAll :: MonadCatch m => (SomeException -> m a) -> m a -> m a
handleAll :: MonadCatch m => (SomeExceptionWithBacktrace -> m a) -> m a -> m a
handleAll = handle
-- | Flipped 'catchIf'
......
......@@ -91,11 +91,11 @@ import Data.Traversable as Traversable
-- >>> runCatchT $ (throwM (ErrorCall "Hello!") :: CatchT IO ()) `catch` (\(e :: ErrorCall) -> liftIO $ print e)
-- Hello!
newtype CatchT m a = CatchT { runCatchT :: m (Either SomeException a) }
newtype CatchT m a = CatchT { runCatchT :: m (Either SomeExceptionWithBacktrace a) }
type Catch = CatchT Identity
runCatch :: Catch a -> Either SomeException a
runCatch :: Catch a -> Either SomeExceptionWithBacktrace a
runCatch = runIdentity . runCatchT
instance Monad m => Functor (CatchT m) where
......@@ -212,7 +212,7 @@ instance MonadRWS r w s m => MonadRWS r w s (CatchT m)
-- | Map the unwrapped computation using the given function.
--
-- @'runCatchT' ('mapCatchT' f m) = f ('runCatchT' m)@
mapCatchT :: (m (Either SomeException a) -> n (Either SomeException b))
mapCatchT :: (m (Either SomeExceptionWithBacktrace a) -> n (Either SomeExceptionWithBacktrace b))
-> CatchT m a
-> CatchT n b
mapCatchT f m = CatchT $ f (runCatchT m)
......@@ -120,7 +120,7 @@ tests = testGroup "Control.Monad.Catch.Tests" $
--, SomeMSpec mspecContTIO
, SomeMSpec mspecCatchTIdentity
, SomeMSpec mspecEitherSomeException
, SomeMSpec mspecEitherSomeExceptionWithBacktrace
]
mspecIO :: MSpec IO
......@@ -168,8 +168,8 @@ tests = testGroup "Control.Monad.Catch.Tests" $
mspecCatchTIdentity :: MSpec Catch
mspecCatchTIdentity = MSpec "Catch" $ fromRight . runCatch
mspecEitherSomeException :: MSpec (Either SomeException)
mspecEitherSomeException = MSpec "Either SomeException" fromRight
mspecEitherSomeExceptionWithBacktrace :: MSpec (Either SomeExceptionWithBacktrace)
mspecEitherSomeExceptionWithBacktrace = MSpec "Either SomeExceptionWithBacktrace" fromRight
tfst :: (Property, ()) -> Property = fst
fromRight (Left _) = error "fromRight"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment