[Haskell-cafe] Control.Exception try and catch

Mads Lindstrøm mads.lindstroem at gmail.com
Wed Apr 28 09:45:19 EDT 2010


Hi

From
http://haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0.0/Control-Exception.html#3

"... The difference between using try and catch for recovery is that in
catch the handler is inside an implicit block (see "Asynchronous
Exceptions") which is important when catching asynchronous
exceptions ..."

However, 'try' is implemented by calling catch
http://haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0.0/src/Control-Exception-Base.html#try:

try :: Exception e => IO a -> IO (Either e a)
try a = catch (a >>= \ v -> return (Right v)) (\e -> return (Left e))

Thus, I wonder, why do 'try' not "inherit" the implicit block mentioned above?

Looking at catch:

catch   :: Exception e
        => IO a         -- ^ The computation to run
        -> (e -> IO a)  -- ^ Handler to invoke if an exception is raised
        -> IO a
catch io h = H'98.catch  io  (h . fromJust . fromException . toException)


I see no call to 'block'. But maybe it is hidden in H'98.catch? And is H'98.catch == Prelude.catch ?

/Mads






More information about the Haskell-Cafe mailing list