Sophie

Sophie

distrib > Mageia > 5 > i586 > media > core-release > by-pkgid > 6e204a966e8c42d976f99a1700ce5f20 > files > 2222

ghc-7.4.2-4.mga5.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Control.Exception</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[
window.onload = function () {pageLoad();setSynopsis("mini_Control-Exception.html");};
//]]>
</script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">base-4.5.1.0: Basic libraries</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Portability</th><td>non-portable (extended exceptions)</td></tr><tr><th>Stability</th><td>experimental</td></tr><tr><th>Maintainer</th><td>libraries@haskell.org</td></tr><tr><th>Safe Haskell</th><td>Trustworthy</td></tr></table><p class="caption">Control.Exception</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">The Exception type
</a></li><li><a href="#g:2">Throwing exceptions
</a></li><li><a href="#g:3">Catching Exceptions
</a><ul><li><a href="#g:4">Catching all exceptions
</a></li><li><a href="#g:5">The <code>catch</code> functions
</a></li><li><a href="#g:6">The <code>handle</code> functions
</a></li><li><a href="#g:7">The <code>try</code> functions
</a></li><li><a href="#g:8">The <code>evaluate</code> function
</a></li><li><a href="#g:9">The <code>mapException</code> function
</a></li></ul></li><li><a href="#g:10">Asynchronous Exceptions
</a><ul><li><a href="#g:11">Asynchronous exception control
</a></li><li><a href="#g:12">(deprecated) Asynchronous exception control
</a><ul><li><a href="#g:13">Applying <code>mask</code> to an exception handler
</a></li><li><a href="#g:14">Interruptible operations
</a></li></ul></li></ul></li><li><a href="#g:15">Assertions
</a></li><li><a href="#g:16">Utilities
</a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>This module provides support for raising and catching both built-in
 and user-defined exceptions.
</p><p>In addition to exceptions thrown by <code><a href="System-IO.html#t:IO">IO</a></code> operations, exceptions may
 be thrown by pure code (imprecise exceptions) or by external events
 (asynchronous exceptions), but may only be caught in the <code><a href="System-IO.html#t:IO">IO</a></code> monad.
 For more details, see:
</p><ul><li> <em>A semantics for imprecise exceptions</em>, by Simon Peyton Jones,
    Alastair Reid, Tony Hoare, Simon Marlow, Fergus Henderson,
    in <em>PLDI'99</em>.
</li><li> <em>Asynchronous exceptions in Haskell</em>, by Simon Marlow, Simon Peyton
    Jones, Andy Moran and John Reppy, in <em>PLDI'01</em>.
</li><li> <em>An Extensible Dynamically-Typed Hierarchy of Exceptions</em>,
    by Simon Marlow, in <em>Haskell '06</em>.
</li></ul></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><span class="keyword">data</span>  <a href="#t:SomeException">SomeException</a>  = <span class="keyword">forall</span> e . <a href="Control-Exception.html#t:Exception">Exception</a> e =&gt; <a href="#v:SomeException">SomeException</a> e</li><li class="src short"><span class="keyword">class</span> (<a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> e, <a href="Text-Show.html#t:Show">Show</a> e) =&gt; <a href="#t:Exception">Exception</a> e  <span class="keyword">where</span><ul class="subs"><li><a href="#v:toException">toException</a> :: e -&gt; <a href="Control-Exception.html#t:SomeException">SomeException</a></li><li><a href="#v:fromException">fromException</a> :: <a href="Control-Exception.html#t:SomeException">SomeException</a> -&gt; <a href="Data-Maybe.html#t:Maybe">Maybe</a> e</li></ul></li><li class="src short"><span class="keyword">data</span>  <a href="#t:IOException">IOException</a> </li><li class="src short"><span class="keyword">data</span>  <a href="#t:ArithException">ArithException</a> <ul class="subs"><li>= <a href="#v:Overflow">Overflow</a>  </li><li>| <a href="#v:Underflow">Underflow</a>  </li><li>| <a href="#v:LossOfPrecision">LossOfPrecision</a>  </li><li>| <a href="#v:DivideByZero">DivideByZero</a>  </li><li>| <a href="#v:Denormal">Denormal</a>  </li></ul></li><li class="src short"><span class="keyword">data</span>  <a href="#t:ArrayException">ArrayException</a> <ul class="subs"><li>= <a href="#v:IndexOutOfBounds">IndexOutOfBounds</a> <a href="Data-String.html#t:String">String</a>  </li><li>| <a href="#v:UndefinedElement">UndefinedElement</a> <a href="Data-String.html#t:String">String</a>  </li></ul></li><li class="src short"><span class="keyword">data</span>  <a href="#t:AssertionFailed">AssertionFailed</a>  = <a href="#v:AssertionFailed">AssertionFailed</a> <a href="Data-String.html#t:String">String</a></li><li class="src short"><span class="keyword">data</span>  <a href="#t:AsyncException">AsyncException</a> <ul class="subs"><li>= <a href="#v:StackOverflow">StackOverflow</a>  </li><li>| <a href="#v:HeapOverflow">HeapOverflow</a>  </li><li>| <a href="#v:ThreadKilled">ThreadKilled</a>  </li><li>| <a href="#v:UserInterrupt">UserInterrupt</a>  </li></ul></li><li class="src short"><span class="keyword">data</span>  <a href="#t:NonTermination">NonTermination</a>  = <a href="#v:NonTermination">NonTermination</a></li><li class="src short"><span class="keyword">data</span>  <a href="#t:NestedAtomically">NestedAtomically</a>  = <a href="#v:NestedAtomically">NestedAtomically</a></li><li class="src short"><span class="keyword">data</span>  <a href="#t:BlockedIndefinitelyOnMVar">BlockedIndefinitelyOnMVar</a>  = <a href="#v:BlockedIndefinitelyOnMVar">BlockedIndefinitelyOnMVar</a></li><li class="src short"><span class="keyword">data</span>  <a href="#t:BlockedIndefinitelyOnSTM">BlockedIndefinitelyOnSTM</a>  = <a href="#v:BlockedIndefinitelyOnSTM">BlockedIndefinitelyOnSTM</a></li><li class="src short"><span class="keyword">data</span>  <a href="#t:Deadlock">Deadlock</a>  = <a href="#v:Deadlock">Deadlock</a></li><li class="src short"><span class="keyword">data</span>  <a href="#t:NoMethodError">NoMethodError</a>  = <a href="#v:NoMethodError">NoMethodError</a> <a href="Data-String.html#t:String">String</a></li><li class="src short"><span class="keyword">data</span>  <a href="#t:PatternMatchFail">PatternMatchFail</a>  = <a href="#v:PatternMatchFail">PatternMatchFail</a> <a href="Data-String.html#t:String">String</a></li><li class="src short"><span class="keyword">data</span>  <a href="#t:RecConError">RecConError</a>  = <a href="#v:RecConError">RecConError</a> <a href="Data-String.html#t:String">String</a></li><li class="src short"><span class="keyword">data</span>  <a href="#t:RecSelError">RecSelError</a>  = <a href="#v:RecSelError">RecSelError</a> <a href="Data-String.html#t:String">String</a></li><li class="src short"><span class="keyword">data</span>  <a href="#t:RecUpdError">RecUpdError</a>  = <a href="#v:RecUpdError">RecUpdError</a> <a href="Data-String.html#t:String">String</a></li><li class="src short"><span class="keyword">data</span>  <a href="#t:ErrorCall">ErrorCall</a>  = <a href="#v:ErrorCall">ErrorCall</a> <a href="Data-String.html#t:String">String</a></li><li class="src short"><a href="#v:throw">throw</a> :: <a href="Control-Exception.html#t:Exception">Exception</a> e =&gt; e -&gt; a</li><li class="src short"><a href="#v:throwIO">throwIO</a> :: <a href="Control-Exception.html#t:Exception">Exception</a> e =&gt; e -&gt; <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:ioError">ioError</a> ::  <a href="System-IO-Error.html#t:IOError">IOError</a> -&gt; <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:throwTo">throwTo</a> :: <a href="Control-Exception.html#t:Exception">Exception</a> e =&gt; <a href="Control-Concurrent.html#t:ThreadId">ThreadId</a> -&gt; e -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:catch">catch</a> :: <a href="Control-Exception.html#t:Exception">Exception</a> e =&gt; <a href="System-IO.html#t:IO">IO</a> a -&gt; (e -&gt; <a href="System-IO.html#t:IO">IO</a> a) -&gt; <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:catches">catches</a> ::  <a href="System-IO.html#t:IO">IO</a> a -&gt; [<a href="Control-Exception.html#t:Handler">Handler</a> a] -&gt; <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><span class="keyword">data</span>  <a href="#t:Handler">Handler</a> a = <span class="keyword">forall</span> e . <a href="Control-Exception.html#t:Exception">Exception</a> e =&gt; <a href="#v:Handler">Handler</a> (e -&gt; <a href="System-IO.html#t:IO">IO</a> a)</li><li class="src short"><a href="#v:catchJust">catchJust</a> :: <a href="Control-Exception.html#t:Exception">Exception</a> e =&gt; (e -&gt; <a href="Data-Maybe.html#t:Maybe">Maybe</a> b) -&gt; <a href="System-IO.html#t:IO">IO</a> a -&gt; (b -&gt; <a href="System-IO.html#t:IO">IO</a> a) -&gt; <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:handle">handle</a> :: <a href="Control-Exception.html#t:Exception">Exception</a> e =&gt; (e -&gt; <a href="System-IO.html#t:IO">IO</a> a) -&gt; <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:handleJust">handleJust</a> :: <a href="Control-Exception.html#t:Exception">Exception</a> e =&gt; (e -&gt; <a href="Data-Maybe.html#t:Maybe">Maybe</a> b) -&gt; (b -&gt; <a href="System-IO.html#t:IO">IO</a> a) -&gt; <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:try">try</a> :: <a href="Control-Exception.html#t:Exception">Exception</a> e =&gt; <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> (<a href="Data-Either.html#t:Either">Either</a> e a)</li><li class="src short"><a href="#v:tryJust">tryJust</a> :: <a href="Control-Exception.html#t:Exception">Exception</a> e =&gt; (e -&gt; <a href="Data-Maybe.html#t:Maybe">Maybe</a> b) -&gt; <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> (<a href="Data-Either.html#t:Either">Either</a> b a)</li><li class="src short"><a href="#v:evaluate">evaluate</a> ::  a -&gt; <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:mapException">mapException</a> :: (<a href="Control-Exception.html#t:Exception">Exception</a> e1, <a href="Control-Exception.html#t:Exception">Exception</a> e2) =&gt; (e1 -&gt; e2) -&gt; a -&gt; a</li><li class="src short"><a href="#v:mask">mask</a> ::  ((<span class="keyword">forall</span> a.  <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> a) -&gt; <a href="System-IO.html#t:IO">IO</a> b) -&gt; <a href="System-IO.html#t:IO">IO</a> b</li><li class="src short"><a href="#v:mask_">mask_</a> ::  <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:uninterruptibleMask">uninterruptibleMask</a> ::  ((<span class="keyword">forall</span> a.  <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> a) -&gt; <a href="System-IO.html#t:IO">IO</a> b) -&gt; <a href="System-IO.html#t:IO">IO</a> b</li><li class="src short"><a href="#v:uninterruptibleMask_">uninterruptibleMask_</a> ::  <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><span class="keyword">data</span>  <a href="#t:MaskingState">MaskingState</a> <ul class="subs"><li>= <a href="#v:Unmasked">Unmasked</a>  </li><li>| <a href="#v:MaskedInterruptible">MaskedInterruptible</a>  </li><li>| <a href="#v:MaskedUninterruptible">MaskedUninterruptible</a>  </li></ul></li><li class="src short"><a href="#v:getMaskingState">getMaskingState</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="Control-Exception.html#t:MaskingState">MaskingState</a></li><li class="src short"><a href="#v:allowInterrupt">allowInterrupt</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:block">block</a> ::  <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:unblock">unblock</a> ::  <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:blocked">blocked</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:assert">assert</a> ::  <a href="Data-Bool.html#t:Bool">Bool</a> -&gt; a -&gt; a</li><li class="src short"><a href="#v:bracket">bracket</a> ::  <a href="System-IO.html#t:IO">IO</a> a -&gt; (a -&gt; <a href="System-IO.html#t:IO">IO</a> b) -&gt; (a -&gt; <a href="System-IO.html#t:IO">IO</a> c) -&gt; <a href="System-IO.html#t:IO">IO</a> c</li><li class="src short"><a href="#v:bracket_">bracket_</a> ::  <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> b -&gt; <a href="System-IO.html#t:IO">IO</a> c -&gt; <a href="System-IO.html#t:IO">IO</a> c</li><li class="src short"><a href="#v:bracketOnError">bracketOnError</a> ::  <a href="System-IO.html#t:IO">IO</a> a -&gt; (a -&gt; <a href="System-IO.html#t:IO">IO</a> b) -&gt; (a -&gt; <a href="System-IO.html#t:IO">IO</a> c) -&gt; <a href="System-IO.html#t:IO">IO</a> c</li><li class="src short"><a href="#v:finally">finally</a> ::  <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> b -&gt; <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:onException">onException</a> ::  <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> b -&gt; <a href="System-IO.html#t:IO">IO</a> a</li></ul></div><div id="interface"><h1 id="g:1">The Exception type
</h1><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:SomeException" class="def">SomeException</a>  </p><div class="doc"><p>The <code>SomeException</code> type is the root of the exception type hierarchy.
When an exception of type <code>e</code> is thrown, behind the scenes it is
encapsulated in a <code>SomeException</code>.
</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><span class="keyword">forall</span> e . <a href="Control-Exception.html#t:Exception">Exception</a> e =&gt; <a name="v:SomeException" class="def">SomeException</a> e</td><td class="doc empty">&nbsp;</td></tr></table></div><div class="subs instances"><p id="control.i:SomeException" class="caption collapser" onclick="toggleSection('i:SomeException')">Instances</p><div id="section.i:SomeException" class="show"><table><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception.html#t:SomeException">SomeException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception.html#t:SomeException">SomeException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:SomeException">SomeException</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">class</span> (<a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> e, <a href="Text-Show.html#t:Show">Show</a> e) =&gt; <a name="t:Exception" class="def">Exception</a> e  <span class="keyword">where</span></p><div class="doc"><p>Any type that you wish to throw or catch as an exception must be an
instance of the <code>Exception</code> class. The simplest case is a new exception
type directly below the root:
</p><pre> data MyException = ThisException | ThatException
     deriving (Show, Typeable)

 instance Exception MyException
</pre><p>The default method definitions in the <code>Exception</code> class do what we need
in this case. You can now throw and catch <code>ThisException</code> and
<code>ThatException</code> as exceptions:
</p><pre>
*Main&gt; throw ThisException `catch` \e -&gt; putStrLn (&quot;Caught &quot; ++ show (e :: MyException))
Caught ThisException
</pre><p>In more complicated examples, you may wish to define a whole hierarchy
of exceptions:
</p><pre> ---------------------------------------------------------------------
 -- 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
</pre><p>We can now catch a <code>MismatchedParentheses</code> exception as
<code>MismatchedParentheses</code>, <code>SomeFrontendException</code> or
<code>SomeCompilerException</code>, but not other types, e.g. <code>IOException</code>:
</p><pre>
*Main&gt; throw MismatchedParentheses <code>catch</code> e -&gt; putStrLn (&quot;Caught &quot; ++ show (e :: MismatchedParentheses))
Caught MismatchedParentheses
*Main&gt; throw MismatchedParentheses <code>catch</code> e -&gt; putStrLn (&quot;Caught &quot; ++ show (e :: SomeFrontendException))
Caught MismatchedParentheses
*Main&gt; throw MismatchedParentheses <code>catch</code> e -&gt; putStrLn (&quot;Caught &quot; ++ show (e :: SomeCompilerException))
Caught MismatchedParentheses
*Main&gt; throw MismatchedParentheses <code>catch</code> e -&gt; putStrLn (&quot;Caught &quot; ++ show (e :: IOException))
*** Exception: MismatchedParentheses
</pre></div><div class="subs methods"><p class="caption">Methods</p><p class="src"><a name="v:toException" class="def">toException</a> :: e -&gt; <a href="Control-Exception.html#t:SomeException">SomeException</a></p><p class="src"><a name="v:fromException" class="def">fromException</a> :: <a href="Control-Exception.html#t:SomeException">SomeException</a> -&gt; <a href="Data-Maybe.html#t:Maybe">Maybe</a> e</p></div><div class="subs instances"><p id="control.i:Exception" class="caption collapser" onclick="toggleSection('i:Exception')">Instances</p><div id="section.i:Exception" class="show"><table><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:ArithException">ArithException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:ErrorCall">ErrorCall</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:SomeException">SomeException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:IOException">IOException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Data-Dynamic.html#t:Dynamic">Dynamic</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="System-Exit.html#t:ExitCode">ExitCode</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:ArrayException">ArrayException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:AsyncException">AsyncException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:AssertionFailed">AssertionFailed</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:Deadlock">Deadlock</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:BlockedIndefinitelyOnSTM">BlockedIndefinitelyOnSTM</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:BlockedIndefinitelyOnMVar">BlockedIndefinitelyOnMVar</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:NestedAtomically">NestedAtomically</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:NonTermination">NonTermination</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:NoMethodError">NoMethodError</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:RecUpdError">RecUpdError</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:RecConError">RecConError</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:RecSelError">RecSelError</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:PatternMatchFail">PatternMatchFail</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-OldException.html#t:Exception">Exception</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> BlockedIndefinitely</td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> BlockedOnDeadMVar</td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> Timeout</td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:IOException" class="def">IOException</a>  </p><div class="doc"><p>Exceptions that occur in the <code>IO</code> monad.
 An <code>IOException</code> records a more specific error type, a descriptive
 string and maybe the handle that was used when the error was
 flagged.
</p></div><div class="subs instances"><p id="control.i:IOException" class="caption collapser" onclick="toggleSection('i:IOException')">Instances</p><div id="section.i:IOException" class="show"><table><tr><td class="src"><a href="Data-Eq.html#t:Eq">Eq</a> <a href="Control-Exception.html#t:IOException">IOException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception.html#t:IOException">IOException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception.html#t:IOException">IOException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:IOException">IOException</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:ArithException" class="def">ArithException</a>  </p><div class="doc"><p>Arithmetic exceptions.
</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:Overflow" class="def">Overflow</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a name="v:Underflow" class="def">Underflow</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a name="v:LossOfPrecision" class="def">LossOfPrecision</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a name="v:DivideByZero" class="def">DivideByZero</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a name="v:Denormal" class="def">Denormal</a></td><td class="doc empty">&nbsp;</td></tr></table></div><div class="subs instances"><p id="control.i:ArithException" class="caption collapser" onclick="toggleSection('i:ArithException')">Instances</p><div id="section.i:ArithException" class="show"><table><tr><td class="src"><a href="Data-Eq.html#t:Eq">Eq</a> <a href="Control-Exception.html#t:ArithException">ArithException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Ord.html#t:Ord">Ord</a> <a href="Control-Exception.html#t:ArithException">ArithException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception.html#t:ArithException">ArithException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception.html#t:ArithException">ArithException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:ArithException">ArithException</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:ArrayException" class="def">ArrayException</a>  </p><div class="doc"><p>Exceptions generated by array operations
</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:IndexOutOfBounds" class="def">IndexOutOfBounds</a> <a href="Data-String.html#t:String">String</a></td><td class="doc"><p>An attempt was made to index an array outside
 its declared bounds.
</p></td></tr><tr><td class="src"><a name="v:UndefinedElement" class="def">UndefinedElement</a> <a href="Data-String.html#t:String">String</a></td><td class="doc"><p>An attempt was made to evaluate an element of an
 array that had not been initialized.
</p></td></tr></table></div><div class="subs instances"><p id="control.i:ArrayException" class="caption collapser" onclick="toggleSection('i:ArrayException')">Instances</p><div id="section.i:ArrayException" class="show"><table><tr><td class="src"><a href="Data-Eq.html#t:Eq">Eq</a> <a href="Control-Exception.html#t:ArrayException">ArrayException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Ord.html#t:Ord">Ord</a> <a href="Control-Exception.html#t:ArrayException">ArrayException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception.html#t:ArrayException">ArrayException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception.html#t:ArrayException">ArrayException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:ArrayException">ArrayException</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:AssertionFailed" class="def">AssertionFailed</a>  </p><div class="doc"><p><code><a href="Control-Exception.html#v:assert">assert</a></code> was applied to <code><a href="Data-Bool.html#v:False">False</a></code>.
</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:AssertionFailed" class="def">AssertionFailed</a> <a href="Data-String.html#t:String">String</a></td><td class="doc empty">&nbsp;</td></tr></table></div><div class="subs instances"><p id="control.i:AssertionFailed" class="caption collapser" onclick="toggleSection('i:AssertionFailed')">Instances</p><div id="section.i:AssertionFailed" class="show"><table><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception.html#t:AssertionFailed">AssertionFailed</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception.html#t:AssertionFailed">AssertionFailed</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:AssertionFailed">AssertionFailed</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:AsyncException" class="def">AsyncException</a>  </p><div class="doc"><p>Asynchronous exceptions.
</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:StackOverflow" class="def">StackOverflow</a></td><td class="doc"><p>The current thread's stack exceeded its limit.
 Since an exception has been raised, the thread's stack
 will certainly be below its limit again, but the
 programmer should take remedial action
 immediately.
</p></td></tr><tr><td class="src"><a name="v:HeapOverflow" class="def">HeapOverflow</a></td><td class="doc"><p>The program's heap is reaching its limit, and
 the program should take action to reduce the amount of
 live data it has. Notes:
</p><ul><li> It is undefined which thread receives this exception.
</li><li> GHC currently does not throw <code><a href="Control-Exception.html#v:HeapOverflow">HeapOverflow</a></code> exceptions.
</li></ul></td></tr><tr><td class="src"><a name="v:ThreadKilled" class="def">ThreadKilled</a></td><td class="doc"><p>This exception is raised by another thread
 calling <code><a href="Control-Concurrent.html#v:killThread">killThread</a></code>, or by the system
 if it needs to terminate the thread for some
 reason.
</p></td></tr><tr><td class="src"><a name="v:UserInterrupt" class="def">UserInterrupt</a></td><td class="doc"><p>This exception is raised by default in the main thread of
 the program when the user requests to terminate the program
 via the usual mechanism(s) (e.g. Control-C in the console).
</p></td></tr></table></div><div class="subs instances"><p id="control.i:AsyncException" class="caption collapser" onclick="toggleSection('i:AsyncException')">Instances</p><div id="section.i:AsyncException" class="show"><table><tr><td class="src"><a href="Data-Eq.html#t:Eq">Eq</a> <a href="Control-Exception.html#t:AsyncException">AsyncException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Ord.html#t:Ord">Ord</a> <a href="Control-Exception.html#t:AsyncException">AsyncException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception.html#t:AsyncException">AsyncException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception.html#t:AsyncException">AsyncException</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:AsyncException">AsyncException</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:NonTermination" class="def">NonTermination</a>  </p><div class="doc"><p>Thrown when the runtime system detects that the computation is
 guaranteed not to terminate. Note that there is no guarantee that
 the runtime system will notice whether any given computation is
 guaranteed to terminate or not.
</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:NonTermination" class="def">NonTermination</a></td><td class="doc empty">&nbsp;</td></tr></table></div><div class="subs instances"><p id="control.i:NonTermination" class="caption collapser" onclick="toggleSection('i:NonTermination')">Instances</p><div id="section.i:NonTermination" class="show"><table><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception.html#t:NonTermination">NonTermination</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception.html#t:NonTermination">NonTermination</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:NonTermination">NonTermination</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:NestedAtomically" class="def">NestedAtomically</a>  </p><div class="doc"><p>Thrown when the program attempts to call <code>atomically</code>, from the <code>stm</code>
 package, inside another call to <code>atomically</code>.
</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:NestedAtomically" class="def">NestedAtomically</a></td><td class="doc empty">&nbsp;</td></tr></table></div><div class="subs instances"><p id="control.i:NestedAtomically" class="caption collapser" onclick="toggleSection('i:NestedAtomically')">Instances</p><div id="section.i:NestedAtomically" class="show"><table><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception.html#t:NestedAtomically">NestedAtomically</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception.html#t:NestedAtomically">NestedAtomically</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:NestedAtomically">NestedAtomically</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:BlockedIndefinitelyOnMVar" class="def">BlockedIndefinitelyOnMVar</a>  </p><div class="doc"><p>The thread is blocked on an <code>MVar</code>, but there are no other references
 to the <code>MVar</code> so it can't ever continue.
</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:BlockedIndefinitelyOnMVar" class="def">BlockedIndefinitelyOnMVar</a></td><td class="doc empty">&nbsp;</td></tr></table></div><div class="subs instances"><p id="control.i:BlockedIndefinitelyOnMVar" class="caption collapser" onclick="toggleSection('i:BlockedIndefinitelyOnMVar')">Instances</p><div id="section.i:BlockedIndefinitelyOnMVar" class="show"><table><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception.html#t:BlockedIndefinitelyOnMVar">BlockedIndefinitelyOnMVar</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception.html#t:BlockedIndefinitelyOnMVar">BlockedIndefinitelyOnMVar</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:BlockedIndefinitelyOnMVar">BlockedIndefinitelyOnMVar</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:BlockedIndefinitelyOnSTM" class="def">BlockedIndefinitelyOnSTM</a>  </p><div class="doc"><p>The thread is waiting to retry an STM transaction, but there are no
 other references to any <code>TVar</code>s involved, so it can't ever continue.
</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:BlockedIndefinitelyOnSTM" class="def">BlockedIndefinitelyOnSTM</a></td><td class="doc empty">&nbsp;</td></tr></table></div><div class="subs instances"><p id="control.i:BlockedIndefinitelyOnSTM" class="caption collapser" onclick="toggleSection('i:BlockedIndefinitelyOnSTM')">Instances</p><div id="section.i:BlockedIndefinitelyOnSTM" class="show"><table><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception.html#t:BlockedIndefinitelyOnSTM">BlockedIndefinitelyOnSTM</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception.html#t:BlockedIndefinitelyOnSTM">BlockedIndefinitelyOnSTM</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:BlockedIndefinitelyOnSTM">BlockedIndefinitelyOnSTM</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:Deadlock" class="def">Deadlock</a>  </p><div class="doc"><p>There are no runnable threads, so the program is deadlocked.
 The <code>Deadlock</code> exception is raised in the main thread only.
</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:Deadlock" class="def">Deadlock</a></td><td class="doc empty">&nbsp;</td></tr></table></div><div class="subs instances"><p id="control.i:Deadlock" class="caption collapser" onclick="toggleSection('i:Deadlock')">Instances</p><div id="section.i:Deadlock" class="show"><table><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception.html#t:Deadlock">Deadlock</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception.html#t:Deadlock">Deadlock</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:Deadlock">Deadlock</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:NoMethodError" class="def">NoMethodError</a>  </p><div class="doc"><p>A class method without a definition (neither a default definition,
 nor a definition in the appropriate instance) was called. The
 <code>String</code> gives information about which method it was.
</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:NoMethodError" class="def">NoMethodError</a> <a href="Data-String.html#t:String">String</a></td><td class="doc empty">&nbsp;</td></tr></table></div><div class="subs instances"><p id="control.i:NoMethodError" class="caption collapser" onclick="toggleSection('i:NoMethodError')">Instances</p><div id="section.i:NoMethodError" class="show"><table><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception.html#t:NoMethodError">NoMethodError</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception.html#t:NoMethodError">NoMethodError</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:NoMethodError">NoMethodError</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:PatternMatchFail" class="def">PatternMatchFail</a>  </p><div class="doc"><p>A pattern match failed. The <code>String</code> gives information about the
 source location of the pattern.
</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:PatternMatchFail" class="def">PatternMatchFail</a> <a href="Data-String.html#t:String">String</a></td><td class="doc empty">&nbsp;</td></tr></table></div><div class="subs instances"><p id="control.i:PatternMatchFail" class="caption collapser" onclick="toggleSection('i:PatternMatchFail')">Instances</p><div id="section.i:PatternMatchFail" class="show"><table><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception.html#t:PatternMatchFail">PatternMatchFail</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception.html#t:PatternMatchFail">PatternMatchFail</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:PatternMatchFail">PatternMatchFail</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:RecConError" class="def">RecConError</a>  </p><div class="doc"><p>An uninitialised record field was used. The <code>String</code> gives
 information about the source location where the record was
 constructed.
</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:RecConError" class="def">RecConError</a> <a href="Data-String.html#t:String">String</a></td><td class="doc empty">&nbsp;</td></tr></table></div><div class="subs instances"><p id="control.i:RecConError" class="caption collapser" onclick="toggleSection('i:RecConError')">Instances</p><div id="section.i:RecConError" class="show"><table><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception.html#t:RecConError">RecConError</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception.html#t:RecConError">RecConError</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:RecConError">RecConError</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:RecSelError" class="def">RecSelError</a>  </p><div class="doc"><p>A record selector was applied to a constructor without the
 appropriate field. This can only happen with a datatype with
 multiple constructors, where some fields are in one constructor
 but not another. The <code>String</code> gives information about the source
 location of the record selector.
</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:RecSelError" class="def">RecSelError</a> <a href="Data-String.html#t:String">String</a></td><td class="doc empty">&nbsp;</td></tr></table></div><div class="subs instances"><p id="control.i:RecSelError" class="caption collapser" onclick="toggleSection('i:RecSelError')">Instances</p><div id="section.i:RecSelError" class="show"><table><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception.html#t:RecSelError">RecSelError</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception.html#t:RecSelError">RecSelError</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:RecSelError">RecSelError</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:RecUpdError" class="def">RecUpdError</a>  </p><div class="doc"><p>A record update was performed on a constructor without the
 appropriate field. This can only happen with a datatype with
 multiple constructors, where some fields are in one constructor
 but not another. The <code>String</code> gives information about the source
 location of the record update.
</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:RecUpdError" class="def">RecUpdError</a> <a href="Data-String.html#t:String">String</a></td><td class="doc empty">&nbsp;</td></tr></table></div><div class="subs instances"><p id="control.i:RecUpdError" class="caption collapser" onclick="toggleSection('i:RecUpdError')">Instances</p><div id="section.i:RecUpdError" class="show"><table><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception.html#t:RecUpdError">RecUpdError</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception.html#t:RecUpdError">RecUpdError</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:RecUpdError">RecUpdError</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:ErrorCall" class="def">ErrorCall</a>  </p><div class="doc"><p>This is thrown when the user calls <code><a href="Prelude.html#v:error">error</a></code>. The <code>String</code> is the
 argument given to <code><a href="Prelude.html#v:error">error</a></code>.
</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:ErrorCall" class="def">ErrorCall</a> <a href="Data-String.html#t:String">String</a></td><td class="doc empty">&nbsp;</td></tr></table></div><div class="subs instances"><p id="control.i:ErrorCall" class="caption collapser" onclick="toggleSection('i:ErrorCall')">Instances</p><div id="section.i:ErrorCall" class="show"><table><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception.html#t:ErrorCall">ErrorCall</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception.html#t:ErrorCall">ErrorCall</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Control-Exception.html#t:Exception">Exception</a> <a href="Control-Exception.html#t:ErrorCall">ErrorCall</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><h1 id="g:2">Throwing exceptions
</h1><div class="top"><p class="src"><a name="v:throw" class="def">throw</a> :: <a href="Control-Exception.html#t:Exception">Exception</a> e =&gt; e -&gt; a</p><div class="doc"><p>Throw an exception.  Exceptions may be thrown from purely
 functional code, but may only be caught within the <code><a href="System-IO.html#t:IO">IO</a></code> monad.
</p></div></div><div class="top"><p class="src"><a name="v:throwIO" class="def">throwIO</a> :: <a href="Control-Exception.html#t:Exception">Exception</a> e =&gt; e -&gt; <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>A variant of <code><a href="Control-Exception.html#v:throw">throw</a></code> that can only be used within the <code><a href="System-IO.html#t:IO">IO</a></code> monad.
</p><p>Although <code><a href="Control-Exception.html#v:throwIO">throwIO</a></code> has a type that is an instance of the type of <code><a href="Control-Exception.html#v:throw">throw</a></code>, the
 two functions are subtly different:
</p><pre> throw e   `seq` x  ===&gt; throw e
 throwIO e `seq` x  ===&gt; x
</pre><p>The first example will cause the exception <code>e</code> to be raised,
 whereas the second one won't.  In fact, <code><a href="Control-Exception.html#v:throwIO">throwIO</a></code> will only cause
 an exception to be raised when it is used within the <code><a href="System-IO.html#t:IO">IO</a></code> monad.
 The <code><a href="Control-Exception.html#v:throwIO">throwIO</a></code> variant should be used in preference to <code><a href="Control-Exception.html#v:throw">throw</a></code> to
 raise an exception within the <code><a href="System-IO.html#t:IO">IO</a></code> monad because it guarantees
 ordering with respect to other <code><a href="System-IO.html#t:IO">IO</a></code> operations, whereas <code><a href="Control-Exception.html#v:throw">throw</a></code>
 does not.
</p></div></div><div class="top"><p class="src"><a name="v:ioError" class="def">ioError</a> ::  <a href="System-IO-Error.html#t:IOError">IOError</a> -&gt; <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>Raise an <code><a href="System-IO-Error.html#t:IOError">IOError</a></code> in the <code><a href="System-IO.html#t:IO">IO</a></code> monad.
</p></div></div><div class="top"><p class="src"><a name="v:throwTo" class="def">throwTo</a> :: <a href="Control-Exception.html#t:Exception">Exception</a> e =&gt; <a href="Control-Concurrent.html#t:ThreadId">ThreadId</a> -&gt; e -&gt; <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p><code><a href="Control-Exception.html#v:throwTo">throwTo</a></code> raises an arbitrary exception in the target thread (GHC only).
</p><p><code><a href="Control-Exception.html#v:throwTo">throwTo</a></code> does not return until the exception has been raised in the
target thread.
The calling thread can thus be certain that the target
thread has received the exception.  This is a useful property to know
when dealing with race conditions: eg. if there are two threads that
can kill each other, it is guaranteed that only one of the threads
will get to kill the other.
</p><p>Whatever work the target thread was doing when the exception was
raised is not lost: the computation is suspended until required by
another thread.
</p><p>If the target thread is currently making a foreign call, then the
exception will not be raised (and hence <code><a href="Control-Exception.html#v:throwTo">throwTo</a></code> will not return)
until the call has completed.  This is the case regardless of whether
the call is inside a <code><a href="Control-Exception.html#v:mask">mask</a></code> or not.  However, in GHC a foreign call
can be annotated as <code>interruptible</code>, in which case a <code><a href="Control-Exception.html#v:throwTo">throwTo</a></code> will
cause the RTS to attempt to cause the call to return; see the GHC
documentation for more details.
</p><p>Important note: the behaviour of <code><a href="Control-Exception.html#v:throwTo">throwTo</a></code> differs from that described in
the paper &quot;Asynchronous exceptions in Haskell&quot;
(<a href="http://research.microsoft.com/~simonpj/Papers/asynch-exns.htm">http://research.microsoft.com/~simonpj/Papers/asynch-exns.htm</a>).
In the paper, <code><a href="Control-Exception.html#v:throwTo">throwTo</a></code> is non-blocking; but the library implementation adopts
a more synchronous design in which <code><a href="Control-Exception.html#v:throwTo">throwTo</a></code> does not return until the exception
is received by the target thread.  The trade-off is discussed in Section 9 of the paper.
Like any blocking operation, <code><a href="Control-Exception.html#v:throwTo">throwTo</a></code> is therefore interruptible (see Section 5.3 of
the paper).  Unlike other interruptible operations, however, <code><a href="Control-Exception.html#v:throwTo">throwTo</a></code>
is <em>always</em> interruptible, even if it does not actually block.
</p><p>There is no guarantee that the exception will be delivered promptly,
although the runtime will endeavour to ensure that arbitrary
delays don't occur.  In GHC, an exception can only be raised when a
thread reaches a <em>safe point</em>, where a safe point is where memory
allocation occurs.  Some loops do not perform any memory allocation
inside the loop and therefore cannot be interrupted by a <code><a href="Control-Exception.html#v:throwTo">throwTo</a></code>.
</p><p>If the target of <code><a href="Control-Exception.html#v:throwTo">throwTo</a></code> is the calling thread, then the behaviour
is the same as <code><a href="Control-Exception.html#v:throwIO">throwIO</a></code>, except that the exception
is thrown as an asynchronous exception.  This means that if there is
an enclosing pure computation, which would be the case if the current
IO operation is inside <code><a href="System-IO-Unsafe.html#v:unsafePerformIO">unsafePerformIO</a></code> or <code><a href="System-IO-Unsafe.html#v:unsafeInterleaveIO">unsafeInterleaveIO</a></code>, that
computation is not permanently replaced by the exception, but is
suspended as if it had received an asynchronous exception.
</p><p>Note that if <code><a href="Control-Exception.html#v:throwTo">throwTo</a></code> is called with the current thread as the
target, the exception will be thrown even if the thread is currently
inside <code><a href="Control-Exception.html#v:mask">mask</a></code> or <code><a href="Control-Exception.html#v:uninterruptibleMask">uninterruptibleMask</a></code>.
</p></div></div><h1 id="g:3">Catching Exceptions
</h1><div class="doc"><p>There are several functions for catching and examining
exceptions; all of them may only be used from within the
<code><a href="System-IO.html#t:IO">IO</a></code> monad.
</p><p>Here's a rule of thumb for deciding which catch-style function to
use:
</p><ul><li> If you want to do some cleanup in the event that an exception
   is raised, use <code><a href="Control-Exception.html#v:finally">finally</a></code>, <code><a href="Control-Exception.html#v:bracket">bracket</a></code> or <code><a href="Control-Exception.html#v:onException">onException</a></code>.
</li><li> To recover after an exception and do something else, the best
   choice is to use one of the <code><a href="Control-Exception.html#v:try">try</a></code> family.
</li><li> ... unless you are recovering from an asynchronous exception, in which
   case use <code><a href="Control-Exception.html#v:catch">catch</a></code> or <code><a href="Control-Exception.html#v:catchJust">catchJust</a></code>.
</li></ul><p>The difference between using <code><a href="Control-Exception.html#v:try">try</a></code> and <code><a href="Control-Exception.html#v:catch">catch</a></code> for recovery is that in
<code><a href="Control-Exception.html#v:catch">catch</a></code> the handler is inside an implicit <code><a href="Control-Exception.html#v:block">block</a></code> (see &quot;Asynchronous
Exceptions&quot;) which is important when catching asynchronous
exceptions, but when catching other kinds of exception it is
unnecessary.  Furthermore it is possible to accidentally stay inside
the implicit <code><a href="Control-Exception.html#v:block">block</a></code> by tail-calling rather than returning from the
handler, which is why we recommend using <code><a href="Control-Exception.html#v:try">try</a></code> rather than <code><a href="Control-Exception.html#v:catch">catch</a></code> for
ordinary exception recovery.
</p><p>A typical use of <code><a href="Control-Exception.html#v:tryJust">tryJust</a></code> for recovery looks like this:
</p><pre>  do r &lt;- tryJust (guard . isDoesNotExistError) $ getEnv &quot;HOME&quot;
     case r of
       Left  e    -&gt; ...
       Right home -&gt; ...
</pre></div><h2 id="g:4">Catching all exceptions
</h2><div class="doc"><p>It is possible to catch all exceptions, by using the type <code><a href="Control-Exception.html#t:SomeException">SomeException</a></code>:
</p><pre> catch f (\e -&gt; ... (e :: SomeException) ...)
</pre><p>HOWEVER, this is normally not what you want to do!
</p><p>For example, suppose you want to read a file, but if it doesn't exist
then continue as if it contained &quot;&quot;.  You might be tempted to just
catch all exceptions and return &quot;&quot; in the handler. However, this has
all sorts of undesirable consequences.  For example, if the user
presses control-C at just the right moment then the <code><a href="Control-Exception.html#v:UserInterrupt">UserInterrupt</a></code>
exception will be caught, and the program will continue running under
the belief that the file contains &quot;&quot;.  Similarly, if another thread
tries to kill the thread reading the file then the <code><a href="Control-Exception.html#v:ThreadKilled">ThreadKilled</a></code>
exception will be ignored.
</p><p>Instead, you should only catch exactly the exceptions that you really
want. In this case, this would likely be more specific than even
&quot;any IO exception&quot;; a permissions error would likely also want to be
handled differently. Instead, you would probably want something like:
</p><pre> e &lt;- tryJust (guard . isDoesNotExistError) (readFile f)
 let str = either (const &quot;&quot;) id e
</pre><p>There are occassions when you really do need to catch any sort of
exception. However, in most cases this is just so you can do some
cleaning up; you aren't actually interested in the exception itself.
For example, if you open a file then you want to close it again,
whether processing the file executes normally or throws an exception.
However, in these cases you can use functions like <code><a href="Control-Exception.html#v:bracket">bracket</a></code>, <code><a href="Control-Exception.html#v:finally">finally</a></code>
and <code><a href="Control-Exception.html#v:onException">onException</a></code>, which never actually pass you the exception, but
just call the cleanup functions at the appropriate points.
</p><p>But sometimes you really do need to catch any exception, and actually
see what the exception is. One example is at the very top-level of a
program, you may wish to catch any exception, print it to a logfile or
the screen, and then exit gracefully. For these cases, you can use
<code><a href="Control-Exception.html#v:catch">catch</a></code> (or one of the other exception-catching functions) with the
<code><a href="Control-Exception.html#t:SomeException">SomeException</a></code> type.
</p></div><h2 id="g:5">The <code>catch</code> functions
</h2><div class="top"><p class="src"><a name="v:catch" class="def">catch</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="Control-Exception.html#t:Exception">Exception</a> e</td><td class="doc empty">&nbsp;</td></tr><tr><td class="src">=&gt; <a href="System-IO.html#t:IO">IO</a> a</td><td class="doc"><p>The computation to run
</p></td></tr><tr><td class="src">-&gt; (e -&gt; <a href="System-IO.html#t:IO">IO</a> a)</td><td class="doc"><p>Handler to invoke if an exception is raised
</p></td></tr><tr><td class="src">-&gt; <a href="System-IO.html#t:IO">IO</a> a</td><td class="doc empty">&nbsp;</td></tr></table></div><div class="doc"><p>This is the simplest of the exception-catching functions.  It
 takes a single argument, runs it, and if an exception is raised
 the &quot;handler&quot; is executed, with the value of the exception passed as an
 argument.  Otherwise, the result is returned as normal.  For example:
</p><pre>   catch (readFile f)
         (\e -&gt; do let err = show (e :: IOException)
                   hPutStr stderr (&quot;Warning: Couldn't open &quot; ++ f ++ &quot;: &quot; ++ err)
                   return &quot;&quot;)
</pre><p>Note that we have to give a type signature to <code>e</code>, or the program
 will not typecheck as the type is ambiguous. While it is possible
 to catch exceptions of any type, see the section &quot;Catching all
 exceptions&quot; (in <a href="Control-Exception.html">Control.Exception</a>) for an explanation of the problems with doing so.
</p><p>For catching exceptions in pure (non-<code><a href="System-IO.html#t:IO">IO</a></code>) expressions, see the
 function <code><a href="Control-Exception.html#v:evaluate">evaluate</a></code>.
</p><p>Note that due to Haskell's unspecified evaluation order, an
 expression may throw one of several possible exceptions: consider
 the expression <code>(error &quot;urk&quot;) + (1 `div` 0)</code>.  Does
 the expression throw
 <code>ErrorCall &quot;urk&quot;</code>, or <code>DivideByZero</code>?
</p><p>The answer is &quot;it might throw either&quot;; the choice is
 non-deterministic. If you are catching any type of exception then you
 might catch either. If you are calling <code>catch</code> with type
 <code>IO Int -&gt; (ArithException -&gt; IO Int) -&gt; IO Int</code> then the handler may
 get run with <code>DivideByZero</code> as an argument, or an <code>ErrorCall &quot;urk&quot;</code>
 exception may be propogated further up. If you call it again, you
 might get a the opposite behaviour. This is ok, because <code><a href="Control-Exception.html#v:catch">catch</a></code> is an
 <code><a href="System-IO.html#t:IO">IO</a></code> computation.
</p><p>Note that the <a href="Prelude.html">Prelude</a> also exports a function called
 <code><a href="Prelude.html#v:catch">catch</a></code> with a similar type to <code><a href="Control-Exception.html#v:catch">catch</a></code>,
 except that the <a href="Prelude.html">Prelude</a> version only catches the IO and user
 families of exceptions (as required by Haskell 98).
</p><p>We recommend either hiding the <a href="Prelude.html">Prelude</a> version of <code><a href="Prelude.html#v:catch">catch</a></code>
 when importing <a href="Control-Exception.html">Control.Exception</a>:
</p><pre> import Prelude hiding (catch)
</pre><p>or importing <a href="Control-Exception.html">Control.Exception</a> qualified, to avoid name-clashes:
</p><pre> import qualified Control.Exception as C
</pre><p>and then using <code>C.catch</code>
</p></div></div><div class="top"><p class="src"><a name="v:catches" class="def">catches</a> ::  <a href="System-IO.html#t:IO">IO</a> a -&gt; [<a href="Control-Exception.html#t:Handler">Handler</a> a] -&gt; <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>Sometimes you want to catch two different sorts of exception. You could
do something like
</p><pre> f = expr `catch` \ (ex :: ArithException) -&gt; handleArith ex
          `catch` \ (ex :: IOException)    -&gt; handleIO    ex
</pre><p>However, there are a couple of problems with this approach. The first is
that having two exception handlers is inefficient. However, the more
serious issue is that the second exception handler will catch exceptions
in the first, e.g. in the example above, if <code>handleArith</code> throws an
<code>IOException</code> then the second exception handler will catch it.
</p><p>Instead, we provide a function <code><a href="Control-Exception.html#v:catches">catches</a></code>, which would be used thus:
</p><pre> f = expr `catches` [Handler (\ (ex :: ArithException) -&gt; handleArith ex),
                     Handler (\ (ex :: IOException)    -&gt; handleIO    ex)]
</pre></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:Handler" class="def">Handler</a> a </p><div class="doc"><p>You need this when using <code><a href="Control-Exception.html#v:catches">catches</a></code>.
</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><span class="keyword">forall</span> e . <a href="Control-Exception.html#t:Exception">Exception</a> e =&gt; <a name="v:Handler" class="def">Handler</a> (e -&gt; <a href="System-IO.html#t:IO">IO</a> a)</td><td class="doc empty">&nbsp;</td></tr></table></div></div><div class="top"><p class="src"><a name="v:catchJust" class="def">catchJust</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="Control-Exception.html#t:Exception">Exception</a> e</td><td class="doc empty">&nbsp;</td></tr><tr><td class="src">=&gt; (e -&gt; <a href="Data-Maybe.html#t:Maybe">Maybe</a> b)</td><td class="doc"><p>Predicate to select exceptions
</p></td></tr><tr><td class="src">-&gt; <a href="System-IO.html#t:IO">IO</a> a</td><td class="doc"><p>Computation to run
</p></td></tr><tr><td class="src">-&gt; (b -&gt; <a href="System-IO.html#t:IO">IO</a> a)</td><td class="doc"><p>Handler
</p></td></tr><tr><td class="src">-&gt; <a href="System-IO.html#t:IO">IO</a> a</td><td class="doc empty">&nbsp;</td></tr></table></div><div class="doc"><p>The function <code><a href="Control-Exception.html#v:catchJust">catchJust</a></code> is like <code><a href="Control-Exception.html#v:catch">catch</a></code>, but it takes an extra
 argument which is an <em>exception predicate</em>, a function which
 selects which type of exceptions we're interested in.
</p><pre> catchJust (\e -&gt; if isDoesNotExistErrorType (ioeGetErrorType e) then Just () else Nothing)
           (readFile f)
           (\_ -&gt; do hPutStrLn stderr (&quot;No such file: &quot; ++ show f)
                     return &quot;&quot;)
</pre><p>Any other exceptions which are not matched by the predicate
 are re-raised, and may be caught by an enclosing
 <code><a href="Control-Exception.html#v:catch">catch</a></code>, <code><a href="Control-Exception.html#v:catchJust">catchJust</a></code>, etc.
</p></div></div><h2 id="g:6">The <code>handle</code> functions
</h2><div class="top"><p class="src"><a name="v:handle" class="def">handle</a> :: <a href="Control-Exception.html#t:Exception">Exception</a> e =&gt; (e -&gt; <a href="System-IO.html#t:IO">IO</a> a) -&gt; <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>A version of <code><a href="Control-Exception.html#v:catch">catch</a></code> with the arguments swapped around; useful in
 situations where the code for the handler is shorter.  For example:
</p><pre>   do handle (\NonTermination -&gt; exitWith (ExitFailure 1)) $
      ...
</pre></div></div><div class="top"><p class="src"><a name="v:handleJust" class="def">handleJust</a> :: <a href="Control-Exception.html#t:Exception">Exception</a> e =&gt; (e -&gt; <a href="Data-Maybe.html#t:Maybe">Maybe</a> b) -&gt; (b -&gt; <a href="System-IO.html#t:IO">IO</a> a) -&gt; <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>A version of <code><a href="Control-Exception.html#v:catchJust">catchJust</a></code> with the arguments swapped around (see
 <code><a href="Control-Exception.html#v:handle">handle</a></code>).
</p></div></div><h2 id="g:7">The <code>try</code> functions
</h2><div class="top"><p class="src"><a name="v:try" class="def">try</a> :: <a href="Control-Exception.html#t:Exception">Exception</a> e =&gt; <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> (<a href="Data-Either.html#t:Either">Either</a> e a)</p><div class="doc"><p>Similar to <code><a href="Control-Exception.html#v:catch">catch</a></code>, but returns an <code><a href="Data-Either.html#t:Either">Either</a></code> result which is
 <code>(<code><a href="Data-Either.html#v:Right">Right</a></code> a)</code> if no exception of type <code>e</code> was raised, or <code>(<code><a href="Data-Either.html#v:Left">Left</a></code> ex)</code>
 if an exception of type <code>e</code> was raised and its value is <code>ex</code>.
 If any other type of exception is raised than it will be propogated
 up to the next enclosing exception handler.
</p><pre>  try a = catch (Right `liftM` a) (return . Left)
</pre><p>Note that <a href="System-IO-Error.html">System.IO.Error</a> also exports a function called
 <code><a href="System-IO-Error.html#v:try">try</a></code> with a similar type to <code><a href="Control-Exception.html#v:try">try</a></code>,
 except that it catches only the IO and user families of exceptions
 (as required by the Haskell 98 <code>IO</code> module).
</p></div></div><div class="top"><p class="src"><a name="v:tryJust" class="def">tryJust</a> :: <a href="Control-Exception.html#t:Exception">Exception</a> e =&gt; (e -&gt; <a href="Data-Maybe.html#t:Maybe">Maybe</a> b) -&gt; <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> (<a href="Data-Either.html#t:Either">Either</a> b a)</p><div class="doc"><p>A variant of <code><a href="Control-Exception.html#v:try">try</a></code> that takes an exception predicate to select
 which exceptions are caught (c.f. <code><a href="Control-Exception.html#v:catchJust">catchJust</a></code>).  If the exception
 does not match the predicate, it is re-thrown.
</p></div></div><h2 id="g:8">The <code>evaluate</code> function
</h2><div class="top"><p class="src"><a name="v:evaluate" class="def">evaluate</a> ::  a -&gt; <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>Forces its argument to be evaluated to weak head normal form when
 the resultant <code><a href="System-IO.html#t:IO">IO</a></code> action is executed. It can be used to order
 evaluation with respect to other <code><a href="System-IO.html#t:IO">IO</a></code> operations; its semantics are
 given by
</p><pre>   evaluate x `seq` y    ==&gt;  y
   evaluate x `catch` f  ==&gt;  (return $! x) `catch` f
   evaluate x &gt;&gt;= f      ==&gt;  (return $! x) &gt;&gt;= f
</pre><p><em>Note:</em> the first equation implies that <code>(evaluate x)</code> is <em>not</em> the
 same as <code>(return $! x)</code>.  A correct definition is
</p><pre>   evaluate x = (return $! x) &gt;&gt;= return
</pre></div></div><h2 id="g:9">The <code>mapException</code> function
</h2><div class="top"><p class="src"><a name="v:mapException" class="def">mapException</a> :: (<a href="Control-Exception.html#t:Exception">Exception</a> e1, <a href="Control-Exception.html#t:Exception">Exception</a> e2) =&gt; (e1 -&gt; e2) -&gt; a -&gt; a</p><div class="doc"><p>This function maps one exception into another as proposed in the
 paper &quot;A semantics for imprecise exceptions&quot;.
</p></div></div><h1 id="g:10">Asynchronous Exceptions
</h1><div class="doc"><p><a name="AsynchronousExceptions"></a> Asynchronous exceptions are so-called because they arise due to
external influences, and can be raised at any point during execution.
<code><a href="Control-Exception.html#v:StackOverflow">StackOverflow</a></code> and <code><a href="Control-Exception.html#v:HeapOverflow">HeapOverflow</a></code> are two examples of
system-generated asynchronous exceptions.
</p><p>The primary source of asynchronous exceptions, however, is
<code><a href="Control-Exception.html#v:throwTo">throwTo</a></code>:
</p><pre>  throwTo :: ThreadId -&gt; Exception -&gt; IO ()
</pre><p><code><a href="Control-Exception.html#v:throwTo">throwTo</a></code> (also <code><a href="Control-Concurrent.html#v:killThread">killThread</a></code>) allows one
running thread to raise an arbitrary exception in another thread.  The
exception is therefore asynchronous with respect to the target thread,
which could be doing anything at the time it receives the exception.
Great care should be taken with asynchronous exceptions; it is all too
easy to introduce race conditions by the over zealous use of
<code><a href="Control-Exception.html#v:throwTo">throwTo</a></code>.
</p></div><h2 id="g:11">Asynchronous exception control
</h2><div class="doc"><p>The following functions allow a thread to control delivery of
 asynchronous exceptions during a critical region.
</p></div><div class="top"><p class="src"><a name="v:mask" class="def">mask</a> ::  ((<span class="keyword">forall</span> a.  <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> a) -&gt; <a href="System-IO.html#t:IO">IO</a> b) -&gt; <a href="System-IO.html#t:IO">IO</a> b</p><div class="doc"><p>Executes an IO computation with asynchronous
 exceptions <em>masked</em>.  That is, any thread which attempts to raise
 an exception in the current thread with <code><a href="Control-Exception.html#v:throwTo">throwTo</a></code>
 will be blocked until asynchronous exceptions are unmasked again.
</p><p>The argument passed to <code><a href="Control-Exception.html#v:mask">mask</a></code> is a function that takes as its
 argument another function, which can be used to restore the
 prevailing masking state within the context of the masked
 computation.  For example, a common way to use <code><a href="Control-Exception.html#v:mask">mask</a></code> is to protect
 the acquisition of a resource:
</p><pre> mask $ \restore -&gt; do
     x &lt;- acquire
     restore (do_something_with x) `onException` release
     release
</pre><p>This code guarantees that <code>acquire</code> is paired with <code>release</code>, by masking
 asynchronous exceptions for the critical parts. (Rather than write
 this code yourself, it would be better to use
 <code><a href="Control-Exception.html#v:bracket">bracket</a></code> which abstracts the general pattern).
</p><p>Note that the <code>restore</code> action passed to the argument to <code><a href="Control-Exception.html#v:mask">mask</a></code>
 does not necessarily unmask asynchronous exceptions, it just
 restores the masking state to that of the enclosing context.  Thus
 if asynchronous exceptions are already masked, <code><a href="Control-Exception.html#v:mask">mask</a></code> cannot be used
 to unmask exceptions again.  This is so that if you call a library function
 with exceptions masked, you can be sure that the library call will not be
 able to unmask exceptions again.  If you are writing library code and need
 to use asynchronous exceptions, the only way is to create a new thread;
 see <code><a href="Control-Concurrent.html#v:forkIOWithUnmask">forkIOWithUnmask</a></code>.
</p><p>Asynchronous exceptions may still be received while in the masked
 state if the masked thread <em>blocks</em> in certain ways; see
 <a href="Control-Exception.html#interruptible">Control.Exception</a>.
</p><p>Threads created by <code><a href="Control-Concurrent.html#v:forkIO">forkIO</a></code> inherit the masked
 state from the parent; that is, to start a thread in blocked mode,
 use <code>mask_ $ forkIO ...</code>.  This is particularly useful if you need
 to establish an exception handler in the forked thread before any
 asynchronous exceptions are received.  To create a a new thread in
 an unmasked state use <code><a href="Control-Concurrent.html#v:forkIOUnmasked">forkIOUnmasked</a></code>.
</p></div></div><div class="top"><p class="src"><a name="v:mask_" class="def">mask_</a> ::  <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>Like <code><a href="Control-Exception.html#v:mask">mask</a></code>, but does not pass a <code>restore</code> action to the argument.
</p></div></div><div class="top"><p class="src"><a name="v:uninterruptibleMask" class="def">uninterruptibleMask</a> ::  ((<span class="keyword">forall</span> a.  <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> a) -&gt; <a href="System-IO.html#t:IO">IO</a> b) -&gt; <a href="System-IO.html#t:IO">IO</a> b</p><div class="doc"><p>Like <code><a href="Control-Exception.html#v:mask">mask</a></code>, but the masked computation is not interruptible (see
 <a href="Control-Exception.html#interruptible">Control.Exception</a>).  THIS SHOULD BE USED WITH
 GREAT CARE, because if a thread executing in <code><a href="Control-Exception.html#v:uninterruptibleMask">uninterruptibleMask</a></code>
 blocks for any reason, then the thread (and possibly the program,
 if this is the main thread) will be unresponsive and unkillable.
 This function should only be necessary if you need to mask
 exceptions around an interruptible operation, and you can guarantee
 that the interruptible operation will only block for a short period
 of time.
</p></div></div><div class="top"><p class="src"><a name="v:uninterruptibleMask_" class="def">uninterruptibleMask_</a> ::  <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>Like <code><a href="Control-Exception.html#v:uninterruptibleMask">uninterruptibleMask</a></code>, but does not pass a <code>restore</code> action
 to the argument.
</p></div></div><div class="top"><p class="src"><span class="keyword">data</span>  <a name="t:MaskingState" class="def">MaskingState</a>  </p><div class="doc"><p>Describes the behaviour of a thread when an asynchronous
 exception is received.
</p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:Unmasked" class="def">Unmasked</a></td><td class="doc"><p>asynchronous exceptions are unmasked (the normal state)
</p></td></tr><tr><td class="src"><a name="v:MaskedInterruptible" class="def">MaskedInterruptible</a></td><td class="doc"><p>the state during <code><a href="Control-Exception.html#v:mask">mask</a></code>: asynchronous exceptions are masked, but blocking operations may still be interrupted
</p></td></tr><tr><td class="src"><a name="v:MaskedUninterruptible" class="def">MaskedUninterruptible</a></td><td class="doc"><p>the state during <code><a href="Control-Exception.html#v:uninterruptibleMask">uninterruptibleMask</a></code>: asynchronous exceptions are masked, and blocking operations may not be interrupted
</p></td></tr></table></div><div class="subs instances"><p id="control.i:MaskingState" class="caption collapser" onclick="toggleSection('i:MaskingState')">Instances</p><div id="section.i:MaskingState" class="show"><table><tr><td class="src"><a href="Data-Eq.html#t:Eq">Eq</a> <a href="Control-Exception.html#t:MaskingState">MaskingState</a></td><td class="doc empty">&nbsp;</td></tr><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception.html#t:MaskingState">MaskingState</a></td><td class="doc empty">&nbsp;</td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:getMaskingState" class="def">getMaskingState</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="Control-Exception.html#t:MaskingState">MaskingState</a></p><div class="doc"><p>Returns the <code><a href="Control-Exception.html#t:MaskingState">MaskingState</a></code> for the current thread.
</p></div></div><div class="top"><p class="src"><a name="v:allowInterrupt" class="def">allowInterrupt</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="../ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></p><div class="doc"><p>When invoked inside <code><a href="Control-Exception.html#v:mask">mask</a></code>, this function allows a blocked
 asynchronous exception to be raised, if one exists.  It is
 equivalent to performing an interruptible operation (see
 <a name="interruptible"></a>), but does not involve any actual blocking.
</p><p>When called outside <code><a href="Control-Exception.html#v:mask">mask</a></code>, or inside <code><a href="Control-Exception.html#v:uninterruptibleMask">uninterruptibleMask</a></code>, this
 function has no effect.
</p></div></div><h2 id="g:12">(deprecated) Asynchronous exception control
</h2><div class="top"><p class="src"><a name="v:block" class="def">block</a> ::  <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>Note: this function is deprecated, please use <code><a href="Control-Exception.html#v:mask">mask</a></code> instead.
</p><p>Applying <code><a href="Control-Exception.html#v:block">block</a></code> to a computation will
 execute that computation with asynchronous exceptions
 <em>blocked</em>.  That is, any thread which
 attempts to raise an exception in the current thread with <code><a href="Control-Exception.html#v:throwTo">throwTo</a></code> will be
 blocked until asynchronous exceptions are unblocked again.  There's
 no need to worry about re-enabling asynchronous exceptions; that is
 done automatically on exiting the scope of
 <code><a href="Control-Exception.html#v:block">block</a></code>.
</p><p>Threads created by <code><a href="Control-Concurrent.html#v:forkIO">forkIO</a></code> inherit the blocked
 state from the parent; that is, to start a thread in blocked mode,
 use <code>block $ forkIO ...</code>.  This is particularly useful if you need to
 establish an exception handler in the forked thread before any
 asynchronous exceptions are received.
</p></div></div><div class="top"><p class="src"><a name="v:unblock" class="def">unblock</a> ::  <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>Note: this function is deprecated, please use <code><a href="Control-Exception.html#v:mask">mask</a></code> instead.
</p><p>To re-enable asynchronous exceptions inside the scope of
 <code><a href="Control-Exception.html#v:block">block</a></code>, <code><a href="Control-Exception.html#v:unblock">unblock</a></code> can be
 used.  It scopes in exactly the same way, so on exit from
 <code><a href="Control-Exception.html#v:unblock">unblock</a></code> asynchronous exception delivery will
 be disabled again.
</p></div></div><div class="top"><p class="src"><a name="v:blocked" class="def">blocked</a> :: <a href="System-IO.html#t:IO">IO</a> <a href="Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p>returns True if asynchronous exceptions are blocked in the
 current thread.
</p></div></div><h3 id="g:13">Applying <code>mask</code> to an exception handler
</h3><div class="doc"><p>There's an implied <code><a href="Control-Exception.html#v:mask">mask</a></code> around every exception handler in a call
to one of the <code><a href="Control-Exception.html#v:catch">catch</a></code> family of functions.  This is because that is
what you want most of the time - it eliminates a common race condition
in starting an exception handler, because there may be no exception
handler on the stack to handle another exception if one arrives
immediately.  If asynchronous exceptions are masked on entering the
handler, though, we have time to install a new exception handler
before being interrupted.  If this weren't the default, one would have
to write something like
</p><pre>      mask $ \restore -&gt;
           catch (restore (...))
                 (\e -&gt; handler)
</pre><p>If you need to unblock asynchronous exceptions again in the exception
handler, <code>restore</code> can be used there too.
</p><p>Note that <code><a href="Control-Exception.html#v:try">try</a></code> and friends <em>do not</em> have a similar default, because
there is no exception handler in this case.  Don't use <code><a href="Control-Exception.html#v:try">try</a></code> for
recovering from an asynchronous exception.
</p></div><h3 id="g:14">Interruptible operations
</h3><div class="doc"><p><a name="interruptible"></a>
Some operations are <em>interruptible</em>, which means that they can receive
asynchronous exceptions even in the scope of a <code><a href="Control-Exception.html#v:mask">mask</a></code>.  Any function
which may itself block is defined as interruptible; this includes
<code><a href="Control-Concurrent-MVar.html#v:takeMVar">takeMVar</a></code>
(but not <code><a href="Control-Concurrent-MVar.html#v:tryTakeMVar">tryTakeMVar</a></code>),
and most operations which perform
some I/O with the outside world.  The reason for having
interruptible operations is so that we can write things like
</p><pre>      mask $ \restore -&gt; do
         a &lt;- takeMVar m
         catch (restore (...))
               (\e -&gt; ...)
</pre><p>if the <code><a href="Control-Concurrent-MVar.html#v:takeMVar">takeMVar</a></code> was not interruptible,
then this particular
combination could lead to deadlock, because the thread itself would be
blocked in a state where it can't receive any asynchronous exceptions.
With <code><a href="Control-Concurrent-MVar.html#v:takeMVar">takeMVar</a></code> interruptible, however, we can be
safe in the knowledge that the thread can receive exceptions right up
until the point when the <code><a href="Control-Concurrent-MVar.html#v:takeMVar">takeMVar</a></code> succeeds.
Similar arguments apply for other interruptible operations like
<code><a href="System-IO.html#v:openFile">openFile</a></code>.
</p><p>It is useful to think of <code><a href="Control-Exception.html#v:mask">mask</a></code> not as a way to completely prevent
asynchronous exceptions, but as a way to switch from asynchronous mode
to polling mode.  The main difficulty with asynchronous
exceptions is that they normally can occur anywhere, but within a
<code><a href="Control-Exception.html#v:mask">mask</a></code> an asynchronous exception is only raised by operations that are
interruptible (or call other interruptible operations).  In many cases
these operations may themselves raise exceptions, such as I/O errors,
so the caller will usually be prepared to handle exceptions arising from the
operation anyway.  To perfom an explicit poll for asynchronous exceptions
inside <code><a href="Control-Exception.html#v:mask">mask</a></code>, use <code><a href="Control-Exception.html#v:allowInterrupt">allowInterrupt</a></code>.
</p><p>Sometimes it is too onerous to handle exceptions in the middle of a
critical piece of stateful code.  There are three ways to handle this
kind of situation:
</p><ul><li> Use STM.  Since a transaction is always either completely executed
   or not at all, transactions are a good way to maintain invariants
   over state in the presence of asynchronous (and indeed synchronous)
   exceptions.
</li><li> Use <code><a href="Control-Exception.html#v:mask">mask</a></code>, and avoid interruptible operations.  In order to do
   this, we have to know which operations are interruptible.  It is
   impossible to know for any given library function whether it might
   invoke an interruptible operation internally; so instead we give a
   list of guaranteed-not-to-be-interruptible operations below.
</li><li> Use <code><a href="Control-Exception.html#v:uninterruptibleMask">uninterruptibleMask</a></code>.  This is generally not recommended,
   unless you can guarantee that any interruptible operations invoked
   during the scope of <code><a href="Control-Exception.html#v:uninterruptibleMask">uninterruptibleMask</a></code> can only ever block for
   a short time.  Otherwise, <code><a href="Control-Exception.html#v:uninterruptibleMask">uninterruptibleMask</a></code> is a good way to
   make your program deadlock and be unresponsive to user interrupts.
</li></ul><p>The following operations are guaranteed not to be interruptible:
</p><ul><li> operations on <code>IORef</code> from <a href="Data-IORef.html">Data.IORef</a>
 * STM transactions that do not use <code>retry</code>
 * everything from the <code>Foreign</code> modules
 * everything from <code>Control.Exception</code>
 * <code>tryTakeMVar</code>, <code>tryPutMVar</code>, <code>isEmptyMVar</code>
 * <code>takeMVar</code> if the <code>MVar</code> is definitely full, and conversely <code>putMVar</code> if the <code>MVar</code> is definitely empty
 * <code>newEmptyMVar</code>, <code>newMVar</code>
 * <code>forkIO</code>, <code>forkIOUnmasked</code>, <code>myThreadId</code>
</li></ul></div><h1 id="g:15">Assertions
</h1><div class="top"><p class="src"><a name="v:assert" class="def">assert</a> ::  <a href="Data-Bool.html#t:Bool">Bool</a> -&gt; a -&gt; a</p><div class="doc"><p>If the first argument evaluates to <code><a href="Data-Bool.html#v:True">True</a></code>, then the result is the
 second argument.  Otherwise an <code>AssertionFailed</code> exception is raised,
 containing a <code><a href="Data-String.html#t:String">String</a></code> with the source file and line number of the
 call to <code><a href="Control-Exception.html#v:assert">assert</a></code>.
</p><p>Assertions can normally be turned on or off with a compiler flag
 (for GHC, assertions are normally on unless optimisation is turned on 
 with <code>-O</code> or the <code>-fignore-asserts</code>
 option is given).  When assertions are turned off, the first
 argument to <code><a href="Control-Exception.html#v:assert">assert</a></code> is ignored, and the second argument is
 returned as the result.
</p></div></div><h1 id="g:16">Utilities
</h1><div class="top"><p class="src"><a name="v:bracket" class="def">bracket</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="System-IO.html#t:IO">IO</a> a</td><td class="doc"><p>computation to run first (&quot;acquire resource&quot;)
</p></td></tr><tr><td class="src">-&gt; (a -&gt; <a href="System-IO.html#t:IO">IO</a> b)</td><td class="doc"><p>computation to run last (&quot;release resource&quot;)
</p></td></tr><tr><td class="src">-&gt; (a -&gt; <a href="System-IO.html#t:IO">IO</a> c)</td><td class="doc"><p>computation to run in-between
</p></td></tr><tr><td class="src">-&gt; <a href="System-IO.html#t:IO">IO</a> c</td><td class="doc empty">&nbsp;</td></tr></table></div><div class="doc"><p>When you want to acquire a resource, do some work with it, and
 then release the resource, it is a good idea to use <code><a href="Control-Exception.html#v:bracket">bracket</a></code>,
 because <code><a href="Control-Exception.html#v:bracket">bracket</a></code> will install the necessary exception handler to
 release the resource in the event that an exception is raised
 during the computation.  If an exception is raised, then <code><a href="Control-Exception.html#v:bracket">bracket</a></code> will
 re-raise the exception (after performing the release).
</p><p>A common example is opening a file:
</p><pre> bracket
   (openFile &quot;filename&quot; ReadMode)
   (hClose)
   (\fileHandle -&gt; do { ... })
</pre><p>The arguments to <code><a href="Control-Exception.html#v:bracket">bracket</a></code> are in this order so that we can partially apply
 it, e.g.:
</p><pre> withFile name mode = bracket (openFile name mode) hClose
</pre></div></div><div class="top"><p class="src"><a name="v:bracket_" class="def">bracket_</a> ::  <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> b -&gt; <a href="System-IO.html#t:IO">IO</a> c -&gt; <a href="System-IO.html#t:IO">IO</a> c</p><div class="doc"><p>A variant of <code><a href="Control-Exception.html#v:bracket">bracket</a></code> where the return value from the first computation
 is not required.
</p></div></div><div class="top"><p class="src"><a name="v:bracketOnError" class="def">bracketOnError</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="System-IO.html#t:IO">IO</a> a</td><td class="doc"><p>computation to run first (&quot;acquire resource&quot;)
</p></td></tr><tr><td class="src">-&gt; (a -&gt; <a href="System-IO.html#t:IO">IO</a> b)</td><td class="doc"><p>computation to run last (&quot;release resource&quot;)
</p></td></tr><tr><td class="src">-&gt; (a -&gt; <a href="System-IO.html#t:IO">IO</a> c)</td><td class="doc"><p>computation to run in-between
</p></td></tr><tr><td class="src">-&gt; <a href="System-IO.html#t:IO">IO</a> c</td><td class="doc empty">&nbsp;</td></tr></table></div><div class="doc"><p>Like <code><a href="Control-Exception.html#v:bracket">bracket</a></code>, but only performs the final action if there was an
 exception raised by the in-between computation.
</p></div></div><div class="top"><p class="src"><a name="v:finally" class="def">finally</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="System-IO.html#t:IO">IO</a> a</td><td class="doc"><p>computation to run first
</p></td></tr><tr><td class="src">-&gt; <a href="System-IO.html#t:IO">IO</a> b</td><td class="doc"><p>computation to run afterward (even if an exception
 was raised)
</p></td></tr><tr><td class="src">-&gt; <a href="System-IO.html#t:IO">IO</a> a</td><td class="doc empty">&nbsp;</td></tr></table></div><div class="doc"><p>A specialised variant of <code><a href="Control-Exception.html#v:bracket">bracket</a></code> with just a computation to run
 afterward.
</p></div></div><div class="top"><p class="src"><a name="v:onException" class="def">onException</a> ::  <a href="System-IO.html#t:IO">IO</a> a -&gt; <a href="System-IO.html#t:IO">IO</a> b -&gt; <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>Like <code><a href="Control-Exception.html#v:finally">finally</a></code>, but only performs the final action if there was an
 exception raised by the computation.
</p></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.11.0</p></div></body></html>