Skip to content
Snippets Groups Projects
Commit 6509bb40 authored by Andrzej Rybczak's avatar Andrzej Rybczak Committed by Zubin
Browse files

Adjust catches to properly rethrow exceptions

ghc/ghc!13302 implemented exception
rethrowing proposal, but it didn't adjust `catches`. This fixes it.

(cherry picked from commit 148059fe)
parent 744fda1b
No related branches found
No related tags found
No related merge requests found
......@@ -119,6 +119,7 @@ module GHC.Internal.Control.Exception (
) where
import GHC.Internal.Control.Exception.Base
import GHC.Internal.Exception.Type (ExceptionWithContext(..), whileHandling)
import GHC.Internal.Base
import GHC.Internal.IO (interruptible)
......@@ -149,13 +150,15 @@ Instead, we provide a function 'catches', which would be used thus:
> Handler (\ (ex :: IOException) -> handleIO ex)]
-}
catches :: IO a -> [Handler a] -> IO a
catches io handlers = io `catch` catchesHandler handlers
catchesHandler :: [Handler a] -> SomeException -> IO a
catchesHandler handlers e = foldr tryHandler (throw e) handlers
where tryHandler (Handler handler) res
= case fromException e of
Just e' -> handler e'
catches io handlers = io `catchNoPropagate` catchesHandler handlers
catchesHandler :: [Handler a] -> ExceptionWithContext SomeException -> IO a
catchesHandler handlers ec@(ExceptionWithContext _ e) =
foldr tryHandler (rethrowIO ec) handlers
where
tryHandler (Handler handler) res =
case fromException e of
Just e' -> annotateIO (whileHandling ec) (handler e')
Nothing -> res
-- -----------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment