[Haskell-cafe] ANN: asynchronous-exceptions

Michael Snoyman michael at snoyman.com
Wed Feb 5 14:56:31 UTC 2014

I don't think this package works as expected. Consider the following:

import           Control.Concurrent
import           Control.Exception.Async
import           System.Timeout

main :: IO ()
main = do
    timeout 1000000 $ do
        threadDelay 10000000 `catchSync` \e -> do
            print e
            threadDelay 10000000
    return ()

The expected behavior would be that the timeout- an async exception- would
kill the thread delay, the catch would ignore the async exception, and the
program would exit. In reality, catchSync treats the timeout as a
synchronous exception, prints it, and delays once again. Compare this to
classy-prelude's catchAny, which handles the situation correctly, via the
technique I described in "Catching all exceptions."[1]

In this case, the issue is that the timeout exception type is not
recognized as async, and a special case could be added to handle that
exception type[2]. However, I think the overall approach of determining
*how* an exception was thrown based on *what* was thrown is not tenable.

[2] It's a bit difficult to do so, since IIRC the type is never exported.
But a hack using the Typeable instance- while ugly- is likely possible.

On Wed, Feb 5, 2014 at 1:28 PM, Roman Cheplyaka <roma at ro-che.info> wrote:

> The links are:
> http://hackage.haskell.org/package/asynchronous-exceptions
> https://github.com/feuerbach/asynchronous-exceptions
> * Roman Cheplyaka <roma at ro-che.info> [2014-02-05 13:23:38+0200]
> > It is often useful to distinguish between synchronous and asynchronous
> > exceptions. The common idiom is to run a user-supplied computation
> > catching any synchronous exceptions but allowing asynchronous exceptions
> > (such as user interrupt) pass through.
> >
> > base 4.7 (shipped with GHC 7.8) will have SomeAsyncException type that
> > solves this problem.
> >
> > asynchronous-exceptions is a new package that serves two purposes:
> > * provide compatibility with older `base` versions that lack the
> >   `SomeAsyncException` type
> > * define convenient functions for catching only synchronous exceptions
> >
> > Roman
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140205/133d1a18/attachment.html>

More information about the Haskell-Cafe mailing list