[Haskell-cafe] Catch multiple exceptions using 'Control.Exception'
Erik Hesselink
hesselink at gmail.com
Wed Jul 3 13:35:21 CEST 2013
Perhaps you can use `catches` [0]?
Erik
[0] http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Exception.html#v:catches
On Wed, Jul 3, 2013 at 12:47 PM, Nikita Karetnikov
<nikita at karetnikov.org> wrote:
> 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
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
More information about the Haskell-Cafe
mailing list