Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > c4d4e0e3e3fc929ca09e4d9c28a0446c > files > 12

ghc-MonadCatchIO-transformers-devel-0.2.2.3-1.fc14.i686.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--Rendered using the Haskell Html Library v0.2-->
<HTML
><HEAD
><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"
><TITLE
>Control.Monad.CatchIO</TITLE
><LINK HREF="haddock.css" REL="stylesheet" TYPE="text/css"
><SCRIPT SRC="haddock-util.js" TYPE="text/javascript"
></SCRIPT
><SCRIPT TYPE="text/javascript"
>window.onload = function () {setSynopsis("mini_Control-Monad-CatchIO.html")};</SCRIPT
></HEAD
><BODY
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="topbar"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD
><IMG SRC="haskell_icon.gif" WIDTH="16" HEIGHT="16" ALT=" "
></TD
><TD CLASS="title"
>MonadCatchIO-transformers-0.2.2.3: Monad-transformer compatible version of the Control.Exception module</TD
><TD CLASS="topbut"
><A HREF="src/Control-Monad-CatchIO.html"
>Source code</A
></TD
><TD CLASS="topbut"
><A HREF="index.html"
>Contents</A
></TD
><TD CLASS="topbut"
><A HREF="doc-index.html"
>Index</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="modulebar"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD
><FONT SIZE="6"
>Control.Monad.CatchIO</FONT
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="section4"
><B
>Contents</B
></TD
></TR
><TR
><TD
><DL
><DT
><A HREF="#1"
>Utilities
</A
></DT
></DL
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="section1"
>Synopsis</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="body"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="decl"
><SPAN CLASS="keyword"
>class</SPAN
> <A HREF="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-IO-Class.html#t%3AMonadIO"
>MonadIO</A
> m =&gt; <A HREF="#t%3AMonadCatchIO"
>MonadCatchIO</A
> m  <SPAN CLASS="keyword"
>where</SPAN
></TD
></TR
><TR
><TD CLASS="body"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="decl"
><A HREF="#v%3Acatch"
>catch</A
> :: <A HREF="Control-Monad-CatchIO.html#t%3AException"
>Exception</A
> e =&gt; m a -&gt; (e -&gt; m a) -&gt; m a</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3Ablock"
>block</A
> ::  m a -&gt; m a</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3Aunblock"
>unblock</A
> ::  m a -&gt; m a</TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><SPAN CLASS="keyword"
>class</SPAN
> (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Typeable.html#t%3ATypeable"
>Typeable</A
> e, <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Text-Show.html#t%3AShow"
>Show</A
> e) =&gt; <A HREF="#t%3AException"
>Exception</A
> e  <SPAN CLASS="keyword"
>where</SPAN
></TD
></TR
><TR
><TD CLASS="body"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="decl"
><A HREF="#v%3AtoException"
>toException</A
> :: e -&gt; <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#t%3ASomeException"
>SomeException</A
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3AfromException"
>fromException</A
> :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#t%3ASomeException"
>SomeException</A
> -&gt; <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#t%3AMaybe"
>Maybe</A
> e</TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3Athrow"
>throw</A
> :: (<A HREF="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-IO-Class.html#t%3AMonadIO"
>MonadIO</A
> m, <A HREF="Control-Monad-CatchIO.html#t%3AException"
>Exception</A
> e) =&gt; e -&gt; m a</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3Atry"
>try</A
> :: (<A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m, <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Monad.html#t%3AFunctor"
>Functor</A
> m, <A HREF="Control-Monad-CatchIO.html#t%3AException"
>Exception</A
> e) =&gt; m a -&gt; m (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Either.html#t%3AEither"
>Either</A
> e a)</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3AtryJust"
>tryJust</A
> :: (<A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m, <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Monad.html#t%3AFunctor"
>Functor</A
> m, <A HREF="Control-Monad-CatchIO.html#t%3AException"
>Exception</A
> e) =&gt; (e -&gt; <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#t%3AMaybe"
>Maybe</A
> b) -&gt; m a -&gt; m (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Either.html#t%3AEither"
>Either</A
> b a)</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><SPAN CLASS="keyword"
>data</SPAN
>  <A HREF="#t%3AHandler"
>Handler</A
> m a = <SPAN CLASS="keyword"
>forall</SPAN
> e . <A HREF="Control-Monad-CatchIO.html#t%3AException"
>Exception</A
> e =&gt; <A HREF="#v%3AHandler"
>Handler</A
> (e -&gt; m a)</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3Acatches"
>catches</A
> :: <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m =&gt; m a -&gt; [<A HREF="Control-Monad-CatchIO.html#t%3AHandler"
>Handler</A
> m a] -&gt; m a</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3Abracket"
>bracket</A
> :: <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m =&gt; m a -&gt; (a -&gt; m b) -&gt; (a -&gt; m c) -&gt; m c</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3Abracket_"
>bracket_</A
> :: <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m =&gt; m a -&gt; m b -&gt; m c -&gt; m c</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3AbracketOnError"
>bracketOnError</A
> :: <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m =&gt; m a -&gt; (a -&gt; m b) -&gt; (a -&gt; m c) -&gt; m c</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3Afinally"
>finally</A
> :: <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m =&gt; m a -&gt; m b -&gt; m a</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="#v%3AonException"
>onException</A
> :: <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m =&gt; m a -&gt; m b -&gt; m a</TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="section1"
>Documentation</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><SPAN CLASS="keyword"
>class</SPAN
> <A HREF="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-IO-Class.html#t%3AMonadIO"
>MonadIO</A
> m =&gt; <A NAME="t:MonadCatchIO"
><A NAME="t%3AMonadCatchIO"
></A
></A
><B
>MonadCatchIO</B
> m  <SPAN CLASS="keyword"
>where</SPAN
></TD
><TD CLASS="declbut"
><A HREF="src/Control-Monad-CatchIO.html#MonadCatchIO"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="body"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="section4"
>Methods</TD
></TR
><TR
><TD CLASS="body"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v:catch"
><A NAME="v%3Acatch"
></A
></A
><B
>catch</B
> :: <A HREF="Control-Monad-CatchIO.html#t%3AException"
>Exception</A
> e =&gt; m a -&gt; (e -&gt; m a) -&gt; m a</TD
><TD CLASS="declbut"
><A HREF="src/Control-Monad-CatchIO.html#catch"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="doc"
>Generalized version of <TT
><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#v%3Acatch"
>catch</A
></TT
>
</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v:block"
><A NAME="v%3Ablock"
></A
></A
><B
>block</B
> ::  m a -&gt; m a</TD
><TD CLASS="declbut"
><A HREF="src/Control-Monad-CatchIO.html#block"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="doc"
>Generalized version of <TT
><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#v%3Ablock"
>block</A
></TT
>
</TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v:unblock"
><A NAME="v%3Aunblock"
></A
></A
><B
>unblock</B
> ::  m a -&gt; m a</TD
><TD CLASS="declbut"
><A HREF="src/Control-Monad-CatchIO.html#unblock"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="doc"
>Generalized version of <TT
><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#v%3Aunblock"
>unblock</A
></TT
>
</TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="section4"
><IMG SRC="minus.gif" CLASS="coll" ONCLICK="toggle(this,'i:MonadCatchIO')" ALT="show/hide"
> Instances</TD
></TR
><TR
><TD CLASS="body"
><DIV ID="i:MonadCatchIO" STYLE="display:block;"
><TABLE CLASS="vanilla" CELLSPACING="1" CELLPADDING="0"
><TR
><TD CLASS="decl"
><A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/System-IO.html#t%3AIO"
>IO</A
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m =&gt; <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> (<A HREF="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-Maybe.html#t%3AMaybeT"
>MaybeT</A
> m)</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m =&gt; <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> (<A HREF="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-List.html#t%3AListT"
>ListT</A
> m)</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m =&gt; <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> (<A HREF="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-Identity.html#t%3AIdentityT"
>IdentityT</A
> m)</TD
></TR
><TR
><TD CLASS="decl"
>(<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Monoid.html#t%3AMonoid"
>Monoid</A
> w, <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m) =&gt; <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> (<A HREF="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-Writer-Strict.html#t%3AWriterT"
>WriterT</A
> w m)</TD
></TR
><TR
><TD CLASS="decl"
>(<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Monoid.html#t%3AMonoid"
>Monoid</A
> w, <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m) =&gt; <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> (<A HREF="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-Writer-Lazy.html#t%3AWriterT"
>WriterT</A
> w m)</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m =&gt; <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> (<A HREF="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-State-Strict.html#t%3AStateT"
>StateT</A
> s m)</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m =&gt; <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> (<A HREF="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-State-Lazy.html#t%3AStateT"
>StateT</A
> s m)</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m =&gt; <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> (<A HREF="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-Reader.html#t%3AReaderT"
>ReaderT</A
> r m)</TD
></TR
><TR
><TD CLASS="decl"
>(<A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m, <A HREF="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-Error.html#t%3AError"
>Error</A
> e) =&gt; <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> (<A HREF="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-Error.html#t%3AErrorT"
>ErrorT</A
> e m)</TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m =&gt; <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> (<A HREF="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-Cont.html#t%3AContT"
>ContT</A
> r m)</TD
></TR
><TR
><TD CLASS="decl"
>(<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Monoid.html#t%3AMonoid"
>Monoid</A
> w, <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m) =&gt; <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> (<A HREF="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-RWS-Strict.html#t%3ARWST"
>RWST</A
> r w s m)</TD
></TR
><TR
><TD CLASS="decl"
>(<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Monoid.html#t%3AMonoid"
>Monoid</A
> w, <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m) =&gt; <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> (<A HREF="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-Trans-RWS-Lazy.html#t%3ARWST"
>RWST</A
> r w s m)</TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><SPAN CLASS="keyword"
>class</SPAN
> (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Typeable.html#t%3ATypeable"
>Typeable</A
> e, <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Text-Show.html#t%3AShow"
>Show</A
> e) =&gt; <A NAME="t:Exception"
><A NAME="t%3AException"
></A
></A
><B
>Exception</B
> e  <SPAN CLASS="keyword"
>where</SPAN
></TD
><TD CLASS="declbut"
><A HREF="src/GHC-Exception.html#Exception"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="body"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="ndoc"
><P
>Any type that you wish to throw or catch as an exception must be an
instance of the <TT
>Exception</TT
> class. The simplest case is a new exception
type directly below the root:
</P
><TT
> data MyException = ThisException | ThatException
     deriving (Show, Typeable)

 instance Exception MyException
</TT
><P
>The default method definitions in the <TT
>Exception</TT
> class do what we need
in this case. You can now throw and catch <TT
>ThisException</TT
> and
<TT
>ThatException</TT
> as exceptions:
</P
><TT
>
*Main&gt; throw ThisException catch e -&gt; putStrLn (&quot;Caught &quot; ++ show (e :: MyException))
Caught ThisException
</TT
><P
>In more complicated examples, you may wish to define a whole hierarchy
of exceptions:
</P
><TT
> ---------------------------------------------------------------------
 -- Make the root exception type for all the exceptions in a compiler

 data SomeCompilerException = forall e . Exception e =&gt; SomeCompilerException e
     deriving Typeable

 instance Show SomeCompilerException where
     show (SomeCompilerException e) = show e

 instance Exception SomeCompilerException

 compilerExceptionToException :: Exception e =&gt; e -&gt; SomeException
 compilerExceptionToException = toException . SomeCompilerException

 compilerExceptionFromException :: Exception e =&gt; SomeException -&gt; Maybe e
 compilerExceptionFromException x = do
     SomeCompilerException a &lt;- fromException x
     cast a

 ---------------------------------------------------------------------
 -- Make a subhierarchy for exceptions in the frontend of the compiler

 data SomeFrontendException = forall e . Exception e =&gt; SomeFrontendException e
     deriving Typeable

 instance Show SomeFrontendException where
     show (SomeFrontendException e) = show e

 instance Exception SomeFrontendException where
     toException = compilerExceptionToException
     fromException = compilerExceptionFromException

 frontendExceptionToException :: Exception e =&gt; e -&gt; SomeException
 frontendExceptionToException = toException . SomeFrontendException

 frontendExceptionFromException :: Exception e =&gt; SomeException -&gt; Maybe e
 frontendExceptionFromException x = do
     SomeFrontendException a &lt;- fromException x
     cast a

 ---------------------------------------------------------------------
 -- Make an exception type for a particular frontend compiler exception

 data MismatchedParentheses = MismatchedParentheses
     deriving (Typeable, Show)

 instance Exception MismatchedParentheses where
     toException   = frontendExceptionToException
     fromException = frontendExceptionFromException
</TT
><P
>We can now catch a <TT
>MismatchedParentheses</TT
> exception as
<TT
>MismatchedParentheses</TT
>, <TT
>SomeFrontendException</TT
> or
<TT
>SomeCompilerException</TT
>, but not other types, e.g. <TT
>IOException</TT
>:
</P
><TT
>
*Main&gt; throw MismatchedParentheses catch e -&gt; putStrLn (&quot;Caught &quot; ++ show (e :: MismatchedParentheses))
Caught MismatchedParentheses
*Main&gt; throw MismatchedParentheses catch e -&gt; putStrLn (&quot;Caught &quot; ++ show (e :: SomeFrontendException))
Caught MismatchedParentheses
*Main&gt; throw MismatchedParentheses catch e -&gt; putStrLn (&quot;Caught &quot; ++ show (e :: SomeCompilerException))
Caught MismatchedParentheses
*Main&gt; throw MismatchedParentheses catch e -&gt; putStrLn (&quot;Caught &quot; ++ show (e :: IOException))
*** Exception: MismatchedParentheses
</TT
></TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="section4"
>Methods</TD
></TR
><TR
><TD CLASS="body"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v:toException"
><A NAME="v%3AtoException"
></A
></A
><B
>toException</B
> :: e -&gt; <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#t%3ASomeException"
>SomeException</A
></TD
><TD CLASS="declbut"
><A HREF="src/GHC-Exception.html#toException"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v:fromException"
><A NAME="v%3AfromException"
></A
></A
><B
>fromException</B
> :: <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#t%3ASomeException"
>SomeException</A
> -&gt; <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#t%3AMaybe"
>Maybe</A
> e</TD
><TD CLASS="declbut"
><A HREF="src/GHC-Exception.html#fromException"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s8"
></TD
></TR
><TR
><TD CLASS="section4"
><IMG SRC="minus.gif" CLASS="coll" ONCLICK="toggle(this,'i:Exception')" ALT="show/hide"
> Instances</TD
></TR
><TR
><TD CLASS="body"
><DIV ID="i:Exception" STYLE="display:block;"
><TABLE CLASS="vanilla" CELLSPACING="1" CELLPADDING="0"
><TR
><TD CLASS="decl"
><A HREF="Control-Monad-CatchIO.html#t%3AException"
>Exception</A
> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#t%3APatternMatchFail"
>PatternMatchFail</A
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Control-Monad-CatchIO.html#t%3AException"
>Exception</A
> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#t%3ARecSelError"
>RecSelError</A
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Control-Monad-CatchIO.html#t%3AException"
>Exception</A
> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#t%3ARecConError"
>RecConError</A
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Control-Monad-CatchIO.html#t%3AException"
>Exception</A
> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#t%3ARecUpdError"
>RecUpdError</A
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Control-Monad-CatchIO.html#t%3AException"
>Exception</A
> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#t%3ANoMethodError"
>NoMethodError</A
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Control-Monad-CatchIO.html#t%3AException"
>Exception</A
> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#t%3ANonTermination"
>NonTermination</A
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Control-Monad-CatchIO.html#t%3AException"
>Exception</A
> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#t%3ANestedAtomically"
>NestedAtomically</A
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Control-Monad-CatchIO.html#t%3AException"
>Exception</A
> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#t%3ASomeException"
>SomeException</A
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Control-Monad-CatchIO.html#t%3AException"
>Exception</A
> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#t%3AErrorCall"
>ErrorCall</A
></TD
></TR
><TR
><TD CLASS="decl"
><A HREF="Control-Monad-CatchIO.html#t%3AException"
>Exception</A
> <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#t%3AArithException"
>ArithException</A
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v:throw"
><A NAME="v%3Athrow"
></A
></A
><B
>throw</B
> :: (<A HREF="/usr/share/doc/ghc/html/libraries/transformers-0.2.2.0/Control-Monad-IO-Class.html#t%3AMonadIO"
>MonadIO</A
> m, <A HREF="Control-Monad-CatchIO.html#t%3AException"
>Exception</A
> e) =&gt; e -&gt; m a</TD
><TD CLASS="declbut"
><A HREF="src/Control-Monad-CatchIO.html#throw"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="doc"
>Generalized version of <TT
><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#v%3AthrowIO"
>throwIO</A
></TT
>
</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v:try"
><A NAME="v%3Atry"
></A
></A
><B
>try</B
> :: (<A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m, <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Monad.html#t%3AFunctor"
>Functor</A
> m, <A HREF="Control-Monad-CatchIO.html#t%3AException"
>Exception</A
> e) =&gt; m a -&gt; m (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Either.html#t%3AEither"
>Either</A
> e a)</TD
><TD CLASS="declbut"
><A HREF="src/Control-Monad-CatchIO.html#try"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="doc"
>Generalized version of <TT
><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#v%3Atry"
>try</A
></TT
>
</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v:tryJust"
><A NAME="v%3AtryJust"
></A
></A
><B
>tryJust</B
> :: (<A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m, <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Monad.html#t%3AFunctor"
>Functor</A
> m, <A HREF="Control-Monad-CatchIO.html#t%3AException"
>Exception</A
> e) =&gt; (e -&gt; <A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Maybe.html#t%3AMaybe"
>Maybe</A
> b) -&gt; m a -&gt; m (<A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Data-Either.html#t%3AEither"
>Either</A
> b a)</TD
><TD CLASS="declbut"
><A HREF="src/Control-Monad-CatchIO.html#tryJust"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="doc"
>Generalized version of <TT
><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#v%3AtryJust"
>tryJust</A
></TT
>
</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><SPAN CLASS="keyword"
>data</SPAN
>  <A NAME="t:Handler"
><A NAME="t%3AHandler"
></A
></A
><B
>Handler</B
> m a </TD
><TD CLASS="declbut"
><A HREF="src/Control-Monad-CatchIO.html#Handler"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="body"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="ndoc"
>Generalized version of <TT
><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception.html#t%3AHandler"
>Handler</A
></TT
>
</TD
></TR
><TR
><TD CLASS="section4"
>Constructors</TD
></TR
><TR
><TD CLASS="body"
><TABLE CLASS="vanilla" CELLSPACING="1" CELLPADDING="0"
><TR
><TD CLASS="arg"
><SPAN CLASS="keyword"
>forall</SPAN
> e . <A HREF="Control-Monad-CatchIO.html#t%3AException"
>Exception</A
> e =&gt; <A NAME="v:Handler"
><A NAME="v%3AHandler"
></A
></A
><B
>Handler</B
> (e -&gt; m a)</TD
><TD CLASS="rdoc"
></TD
></TR
></TABLE
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v:catches"
><A NAME="v%3Acatches"
></A
></A
><B
>catches</B
> :: <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m =&gt; m a -&gt; [<A HREF="Control-Monad-CatchIO.html#t%3AHandler"
>Handler</A
> m a] -&gt; m a</TD
><TD CLASS="declbut"
><A HREF="src/Control-Monad-CatchIO.html#catches"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="doc"
>Generalized version of <TT
><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception.html#v%3Acatches"
>catches</A
></TT
>
</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="section1"
><A NAME="1"
><A NAME="1"
>Utilities
</A
></A
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v:bracket"
><A NAME="v%3Abracket"
></A
></A
><B
>bracket</B
> :: <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m =&gt; m a -&gt; (a -&gt; m b) -&gt; (a -&gt; m c) -&gt; m c</TD
><TD CLASS="declbut"
><A HREF="src/Control-Monad-CatchIO.html#bracket"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="doc"
>Generalized version of <TT
><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#v%3Abracket"
>bracket</A
></TT
>
</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v:bracket_"
><A NAME="v%3Abracket_"
></A
></A
><B
>bracket_</B
></TD
><TD CLASS="declbut"
><A HREF="src/Control-Monad-CatchIO.html#bracket_"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="body"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="arg"
>:: <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m</TD
><TD CLASS="rdoc"
></TD
></TR
><TR
><TD CLASS="arg"
>=&gt; m a</TD
><TD CLASS="rdoc"
>computation to run first (&quot;acquire resource&quot;)
</TD
></TR
><TR
><TD CLASS="arg"
>-&gt; m b</TD
><TD CLASS="rdoc"
>computation to run last (&quot;release resource&quot;)
</TD
></TR
><TR
><TD CLASS="arg"
>-&gt; m c</TD
><TD CLASS="rdoc"
>computation to run in-between
</TD
></TR
><TR
><TD CLASS="arg"
>-&gt; m c</TD
><TD CLASS="rdoc"
></TD
></TR
><TR
><TD CLASS="ndoc" COLSPAN="2"
>A variant of <TT
><A HREF="Control-Monad-CatchIO.html#v%3Abracket"
>bracket</A
></TT
> where the return value from the first computation
 is not required.
</TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v:bracketOnError"
><A NAME="v%3AbracketOnError"
></A
></A
><B
>bracketOnError</B
></TD
><TD CLASS="declbut"
><A HREF="src/Control-Monad-CatchIO.html#bracketOnError"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="body"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="arg"
>:: <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m</TD
><TD CLASS="rdoc"
></TD
></TR
><TR
><TD CLASS="arg"
>=&gt; m a</TD
><TD CLASS="rdoc"
>computation to run first (&quot;acquire resource&quot;)
</TD
></TR
><TR
><TD CLASS="arg"
>-&gt; a -&gt; m b</TD
><TD CLASS="rdoc"
>computation to run last (&quot;release resource&quot;)
</TD
></TR
><TR
><TD CLASS="arg"
>-&gt; a -&gt; m c</TD
><TD CLASS="rdoc"
>computation to run in-between
</TD
></TR
><TR
><TD CLASS="arg"
>-&gt; m c</TD
><TD CLASS="rdoc"
></TD
></TR
><TR
><TD CLASS="ndoc" COLSPAN="2"
>Like <TT
><A HREF="Control-Monad-CatchIO.html#v%3Abracket"
>bracket</A
></TT
>, but only performs the final action if there was an
 exception raised by the in-between computation.
</TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v:finally"
><A NAME="v%3Afinally"
></A
></A
><B
>finally</B
></TD
><TD CLASS="declbut"
><A HREF="src/Control-Monad-CatchIO.html#finally"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="body"
><TABLE CLASS="vanilla" CELLSPACING="0" CELLPADDING="0"
><TR
><TD CLASS="arg"
>:: <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m</TD
><TD CLASS="rdoc"
></TD
></TR
><TR
><TD CLASS="arg"
>=&gt; m a</TD
><TD CLASS="rdoc"
>computation to run first
</TD
></TR
><TR
><TD CLASS="arg"
>-&gt; m b</TD
><TD CLASS="rdoc"
>computation to run afterward (even if an exception was
 raised)
</TD
></TR
><TR
><TD CLASS="arg"
>-&gt; m a</TD
><TD CLASS="rdoc"
></TD
></TR
><TR
><TD CLASS="ndoc" COLSPAN="2"
>A specialised variant of <TT
><A HREF="Control-Monad-CatchIO.html#v%3Abracket"
>bracket</A
></TT
> with just a computation to run
 afterward.
</TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="topdecl"
><TABLE CLASS="declbar"
><TR
><TD CLASS="declname"
><A NAME="v:onException"
><A NAME="v%3AonException"
></A
></A
><B
>onException</B
> :: <A HREF="Control-Monad-CatchIO.html#t%3AMonadCatchIO"
>MonadCatchIO</A
> m =&gt; m a -&gt; m b -&gt; m a</TD
><TD CLASS="declbut"
><A HREF="src/Control-Monad-CatchIO.html#onException"
>Source</A
></TD
></TR
></TABLE
></TD
></TR
><TR
><TD CLASS="doc"
>Generalized version of <TT
><A HREF="/usr/share/doc/ghc/html/libraries/base-4.2.0.2/Control-Exception-Base.html#v%3AonException"
>onException</A
></TT
>
</TD
></TR
><TR
><TD CLASS="s15"
></TD
></TR
><TR
><TD CLASS="botbar"
>Produced by <A HREF="http://www.haskell.org/haddock/"
>Haddock</A
> version 2.6.1</TD
></TR
></TABLE
></BODY
></HTML
>