[Haskell-cafe] Re: Control.Exception try and catch
marlowsd at gmail.com
Wed Apr 28 17:01:59 EDT 2010
On 28/04/10 14:45, Mads Lindstrøm wrote:
> "... 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
> 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?
There's nothing magic going on - the "handler" in the case of try is
just (return . Left), and that does indeed get executed with an implicit
> 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 ?
The block is implicit (it's built into the implementation of catch, in
More information about the Haskell-Cafe