Control.Exception

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Mon Nov 3 12:53:20 EST 2008


On Mon, 2008-11-03 at 09:26 -0800, Sigbjorn Finne wrote:
> On 11/3/2008 07:34, Jason Dagit wrote:
> > ....
> >
> > Ah, but I had one more question that I don't think anyone has answered
> > yet.  That is, how to deal with multiple types of exceptions.
> > Suppose, as a concrete example, that I was looking out for both
> > ExitCode and PatternMatchFail exceptions.  Maybe I'm being naive, but
> > it seems like I'm in that situation again where I have to catch all
> > and then check if fromException succeeds on either PatternMatchFile or
> > ExitCode types.  And then throw if it both give Nothing?
> >
> >   
> One way to do this now is to use Control.Exception.catches:
> 
>  catches :: IO a -> [Handler a] -> IO a
>  data Handler a where
>     Handler :: forall a e. (Exception e) => (e -> IO a) -> Handler a

ie:

action
  `catches`
    [ \(e :: ExitCode) -> ...
    , \(e :: PatternMatchFail) -> ...
    ]

or just by using multiple catch clauses:

action
  `catch` (\(e :: ExitCode) -> ...)
  `catch` (\(e :: PatternMatchFail) -> ...)


Duncan



More information about the Glasgow-haskell-users mailing list