{-# OPTIONS_GHC -fno-warn-deprecations #-}moduleException(moduleControl.Exception,moduleException )whereimportGhcPrelude importControl.ExceptionimportControl.Monad.IO.ClasscatchIO::IOa ->(IOException->IOa )->IOa catchIO =Control.Exception.catchhandleIO::(IOException->IOa )->IOa ->IOa handleIO =flipcatchIO tryIO::IOa ->IO(EitherIOExceptiona )tryIO =try-- | A monad that can catch exceptions. A minimal definition-- requires a definition of 'gcatch'.---- Implementations on top of 'IO' should implement 'gmask' to-- eventually call the primitive 'Control.Exception.mask'.-- These are used for-- implementations that support asynchronous exceptions. The default-- implementations of 'gbracket' and 'gfinally' use 'gmask'-- thus rarely require overriding.--classMonadIOm =>ExceptionMonad m where-- | Generalised version of 'Control.Exception.catch', allowing an arbitrary-- exception handling monad instead of just 'IO'.gcatch ::Exceptione =>m a ->(e ->m a )->m a -- | Generalised version of 'Control.Exception.mask_', allowing an arbitrary-- exception handling monad instead of just 'IO'.gmask ::((m a ->m a )->m b )->m b -- | Generalised version of 'Control.Exception.bracket', allowing an arbitrary-- exception handling monad instead of just 'IO'.gbracket ::m a ->(a ->m b )->(a ->m c )->m c -- | Generalised version of 'Control.Exception.finally', allowing an arbitrary-- exception handling monad instead of just 'IO'.gfinally ::m a ->m b ->m a gbracket before after thing =gmask $\restore ->doa <-before r <-restore (thing a )`gonException `after a _<-after a returnr a `gfinally `sequel =gmask $\restore ->dor <-restore a `gonException `sequel _<-sequel returnr instanceExceptionMonad IOwheregcatch =Control.Exception.catchgmask f =mask(\x ->f x )gtry::(ExceptionMonad m ,Exceptione )=>m a ->m (Eithere a )gtry act =gcatch (act >>=\a ->return(Righta ))(\e ->return(Lefte ))-- | Generalised version of 'Control.Exception.handle', allowing an arbitrary-- exception handling monad instead of just 'IO'.ghandle::(ExceptionMonad m ,Exceptione )=>(e ->m a )->m a ->m a ghandle =flipgcatch -- | Always executes the first argument. If this throws an exception the-- second argument is executed and the exception is raised again.gonException::(ExceptionMonad m )=>m a ->m b ->m a gonException ioA cleanup =ioA `gcatch `\e ->do_<-cleanup liftIO$throwIO(e ::SomeException)

AltStyle によって変換されたページ (->オリジナル) /