[Haskell-cafe] Catch multiple exceptions using 'Control.Exception'

Nikita Karetnikov nikita at karetnikov.org
Wed Jul 3 12:47:20 CEST 2013


I'm trying to update a package that uses 'Control.OldException' (works
with GHC 6.10.4).  Here is a relevant (and simplified) part:

import Control.OldException

-- | A predicate matching synchronous exceptions.
syncExceptions :: Exception -> Maybe Exception
syncExceptions (AsyncException _) = Nothing
syncExceptions e                  = Just e

throwAsync :: IO a
throwAsync = throwIO $ AsyncException StackOverflow

throwArith :: IO a
throwArith = throwIO $ ArithException DivideByZero

'syncExceptions' is usually used like this:

*Main> tryJust syncExceptions throwArith
Left divide by zero
*Main> tryJust syncExceptions throwAsync  -- pass through
*** Exception: stack overflow

The above doesn't work with GHC 7.6.3 because 'Control.OldException' [1]
was removed.  And 'Control.Exception' doesn't have the 'Exception' type.

Is there a way to adapt 'syncExceptions' to work with
'Control.Exception'?

[1] http://hackage.haskell.org/packages/archive/base/4.1.0.0/doc/html/Control-OldException.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130703/c7cb405e/attachment.pgp>


More information about the Haskell-Cafe mailing list