Skip to content
Snippets Groups Projects
Commit 688c6ae2 authored by Simon Marlow's avatar Simon Marlow
Browse files

Fix a bug in catch when the handler has type (SomeException -> IO a)

This was causing certain exceptions in GHC to not get caught
correctly, in particular the "mismatched interface file versions"
error when reading the old interface file.
parent a2983628
No related branches found
No related tags found
No related merge requests found
...@@ -201,26 +201,31 @@ catch :: Exception e ...@@ -201,26 +201,31 @@ catch :: Exception e
=> IO a -- ^ The computation to run => IO a -- ^ The computation to run
-> (e -> IO a) -- ^ Handler to invoke if an exception is raised -> (e -> IO a) -- ^ Handler to invoke if an exception is raised
-> IO a -> IO a
catch io handler = io `E.catch` handler' catch io poly_handler = io `E.catch` handler'
where handler' e = case fromException (toException e) of where
Just e' -> -- First look for "new style" exceptions, which are thrown
-- Handle the case where e == E.Exception, -- as E.DynException (SomeException e)
-- or one of the types that make up E.Exception
handler e' -- needs scoped TVs: handler' :: E.Exception -> IO a
Nothing -> handler' e = case e of
case e of
E.DynException dyn -> E.DynException dyn ->
case fromDynamic dyn of case fromDynamic dyn of
Just (SomeException exc) -> Just se@(SomeException _) ->
case cast exc of case fromException se of
Just e' -> Just e' -> poly_handler e'
-- Handle the case where we have Nothing -> E.throw e
-- a new exception type encoded Nothing -> try_old e
-- as a Dynamic _ -> try_old e
handler e'
Nothing -> E.throw e -- If it's a legacy exception (E.Exception or one of the
Nothing -> E.throw e -- types that make up E.Exception), check for a handler than
_ -> E.throw e -- can handle them:
-- needs scoped TVs: try_old :: E.Exception -> IO a
try_old e = case fromException (toException e) of
Just e' -> poly_handler e'
Nothing -> E.throw e
-- | When you want to acquire a resource, do some work with it, and -- | When you want to acquire a resource, do some work with it, and
-- then release the resource, it is a good idea to use 'bracket', -- then release the resource, it is a good idea to use 'bracket',
......
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