<!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.Base</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-Base.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.Base</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">The <code>catch</code> functions </a></li><li><a href="#g:5">The <code>handle</code> functions </a></li><li><a href="#g:6">The <code>try</code> functions </a></li><li><a href="#g:7">The <code>evaluate</code> function </a></li><li><a href="#g:8">The <code>mapException</code> function </a></li></ul></li><li><a href="#g:9">Asynchronous Exceptions </a><ul><li><a href="#g:10">Asynchronous exception control </a></li><li><a href="#g:11">(deprecated) Asynchronous exception control </a></li></ul></li><li><a href="#g:12">Assertions </a></li><li><a href="#g:13">Utilities </a></li><li><a href="#g:14">Calls for GHC runtime </a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>Extensible exceptions, except for multiple handlers. </p></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-Base.html#t:Exception">Exception</a> e => <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) => <a href="#t:Exception">Exception</a> e <span class="keyword">where</span><ul class="subs"><li><a href="#v:toException">toException</a> :: e -> <a href="Control-Exception-Base.html#t:SomeException">SomeException</a></li><li><a href="#v:fromException">fromException</a> :: <a href="Control-Exception-Base.html#t:SomeException">SomeException</a> -> <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:throwIO">throwIO</a> :: <a href="Control-Exception-Base.html#t:Exception">Exception</a> e => e -> <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:throw">throw</a> :: <a href="Control-Exception-Base.html#t:Exception">Exception</a> e => e -> a</li><li class="src short"><a href="#v:ioError">ioError</a> :: <a href="System-IO-Error.html#t:IOError">IOError</a> -> <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-Base.html#t:Exception">Exception</a> e => <a href="Control-Concurrent.html#t:ThreadId">ThreadId</a> -> e -> <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-Base.html#t:Exception">Exception</a> e => <a href="System-IO.html#t:IO">IO</a> a -> (e -> <a href="System-IO.html#t:IO">IO</a> a) -> <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-Base.html#t:Exception">Exception</a> e => (e -> <a href="Data-Maybe.html#t:Maybe">Maybe</a> b) -> <a href="System-IO.html#t:IO">IO</a> a -> (b -> <a href="System-IO.html#t:IO">IO</a> a) -> <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-Base.html#t:Exception">Exception</a> e => (e -> <a href="System-IO.html#t:IO">IO</a> a) -> <a href="System-IO.html#t:IO">IO</a> a -> <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-Base.html#t:Exception">Exception</a> e => (e -> <a href="Data-Maybe.html#t:Maybe">Maybe</a> b) -> (b -> <a href="System-IO.html#t:IO">IO</a> a) -> <a href="System-IO.html#t:IO">IO</a> a -> <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-Base.html#t:Exception">Exception</a> e => <a href="System-IO.html#t:IO">IO</a> a -> <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-Base.html#t:Exception">Exception</a> e => (e -> <a href="Data-Maybe.html#t:Maybe">Maybe</a> b) -> <a href="System-IO.html#t:IO">IO</a> a -> <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:onException">onException</a> :: <a href="System-IO.html#t:IO">IO</a> a -> <a href="System-IO.html#t:IO">IO</a> b -> <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:evaluate">evaluate</a> :: a -> <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-Base.html#t:Exception">Exception</a> e1, <a href="Control-Exception-Base.html#t:Exception">Exception</a> e2) => (e1 -> e2) -> a -> 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 -> <a href="System-IO.html#t:IO">IO</a> a) -> <a href="System-IO.html#t:IO">IO</a> b) -> <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 -> <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 -> <a href="System-IO.html#t:IO">IO</a> a) -> <a href="System-IO.html#t:IO">IO</a> b) -> <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 -> <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-Base.html#t:MaskingState">MaskingState</a></li><li class="src short"><a href="#v:block">block</a> :: <a href="System-IO.html#t:IO">IO</a> a -> <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 -> <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> -> a -> a</li><li class="src short"><a href="#v:bracket">bracket</a> :: <a href="System-IO.html#t:IO">IO</a> a -> (a -> <a href="System-IO.html#t:IO">IO</a> b) -> (a -> <a href="System-IO.html#t:IO">IO</a> c) -> <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 -> <a href="System-IO.html#t:IO">IO</a> b -> <a href="System-IO.html#t:IO">IO</a> c -> <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 -> (a -> <a href="System-IO.html#t:IO">IO</a> b) -> (a -> <a href="System-IO.html#t:IO">IO</a> c) -> <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 -> <a href="System-IO.html#t:IO">IO</a> b -> <a href="System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:recSelError">recSelError</a> :: <a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:Addr-35-">Addr#</a> -> a</li><li class="src short"><a href="#v:recConError">recConError</a> :: <a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:Addr-35-">Addr#</a> -> a</li><li class="src short"><a href="#v:irrefutPatError">irrefutPatError</a> :: <a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:Addr-35-">Addr#</a> -> a</li><li class="src short"><a href="#v:runtimeError">runtimeError</a> :: <a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:Addr-35-">Addr#</a> -> a</li><li class="src short"><a href="#v:nonExhaustiveGuardsError">nonExhaustiveGuardsError</a> :: <a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:Addr-35-">Addr#</a> -> a</li><li class="src short"><a href="#v:patError">patError</a> :: <a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:Addr-35-">Addr#</a> -> a</li><li class="src short"><a href="#v:noMethodBindingError">noMethodBindingError</a> :: <a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:Addr-35-">Addr#</a> -> a</li><li class="src short"><a href="#v:absentError">absentError</a> :: <a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:Addr-35-">Addr#</a> -> a</li><li class="src short"><a href="#v:nonTermination">nonTermination</a> :: <a href="Control-Exception-Base.html#t:SomeException">SomeException</a></li><li class="src short"><a href="#v:nestedAtomically">nestedAtomically</a> :: <a href="Control-Exception-Base.html#t:SomeException">SomeException</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-Base.html#t:Exception">Exception</a> e => <a name="v:SomeException" class="def">SomeException</a> e</td><td class="doc empty"> </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-Base.html#t:SomeException">SomeException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception-Base.html#t:SomeException">SomeException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:SomeException">SomeException</a></td><td class="doc empty"> </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) => <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> throw ThisException `catch` \e -> putStrLn ("Caught " ++ 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 => SomeCompilerException e deriving Typeable instance Show SomeCompilerException where show (SomeCompilerException e) = show e instance Exception SomeCompilerException compilerExceptionToException :: Exception e => e -> SomeException compilerExceptionToException = toException . SomeCompilerException compilerExceptionFromException :: Exception e => SomeException -> Maybe e compilerExceptionFromException x = do SomeCompilerException a <- fromException x cast a --------------------------------------------------------------------- -- Make a subhierarchy for exceptions in the frontend of the compiler data SomeFrontendException = forall e . Exception e => SomeFrontendException e deriving Typeable instance Show SomeFrontendException where show (SomeFrontendException e) = show e instance Exception SomeFrontendException where toException = compilerExceptionToException fromException = compilerExceptionFromException frontendExceptionToException :: Exception e => e -> SomeException frontendExceptionToException = toException . SomeFrontendException frontendExceptionFromException :: Exception e => SomeException -> Maybe e frontendExceptionFromException x = do SomeFrontendException a <- 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> throw MismatchedParentheses <code>catch</code> e -> putStrLn ("Caught " ++ show (e :: MismatchedParentheses)) Caught MismatchedParentheses *Main> throw MismatchedParentheses <code>catch</code> e -> putStrLn ("Caught " ++ show (e :: SomeFrontendException)) Caught MismatchedParentheses *Main> throw MismatchedParentheses <code>catch</code> e -> putStrLn ("Caught " ++ show (e :: SomeCompilerException)) Caught MismatchedParentheses *Main> throw MismatchedParentheses <code>catch</code> e -> putStrLn ("Caught " ++ 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 -> <a href="Control-Exception-Base.html#t:SomeException">SomeException</a></p><p class="src"><a name="v:fromException" class="def">fromException</a> :: <a href="Control-Exception-Base.html#t:SomeException">SomeException</a> -> <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-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:ArithException">ArithException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:ErrorCall">ErrorCall</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:SomeException">SomeException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:IOException">IOException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Data-Dynamic.html#t:Dynamic">Dynamic</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="System-Exit.html#t:ExitCode">ExitCode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:ArrayException">ArrayException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:AsyncException">AsyncException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:AssertionFailed">AssertionFailed</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:Deadlock">Deadlock</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:BlockedIndefinitelyOnSTM">BlockedIndefinitelyOnSTM</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:BlockedIndefinitelyOnMVar">BlockedIndefinitelyOnMVar</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:NestedAtomically">NestedAtomically</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:NonTermination">NonTermination</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:NoMethodError">NoMethodError</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:RecUpdError">RecUpdError</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:RecConError">RecConError</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:RecSelError">RecSelError</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:PatternMatchFail">PatternMatchFail</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-OldException.html#t:Exception">Exception</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> BlockedIndefinitely</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> BlockedOnDeadMVar</td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> Timeout</td><td class="doc empty"> </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-Base.html#t:IOException">IOException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception-Base.html#t:IOException">IOException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception-Base.html#t:IOException">IOException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:IOException">IOException</a></td><td class="doc empty"> </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"> </td></tr><tr><td class="src"><a name="v:Underflow" class="def">Underflow</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a name="v:LossOfPrecision" class="def">LossOfPrecision</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a name="v:DivideByZero" class="def">DivideByZero</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a name="v:Denormal" class="def">Denormal</a></td><td class="doc empty"> </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-Base.html#t:ArithException">ArithException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ord.html#t:Ord">Ord</a> <a href="Control-Exception-Base.html#t:ArithException">ArithException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception-Base.html#t:ArithException">ArithException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception-Base.html#t:ArithException">ArithException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:ArithException">ArithException</a></td><td class="doc empty"> </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-Base.html#t:ArrayException">ArrayException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ord.html#t:Ord">Ord</a> <a href="Control-Exception-Base.html#t:ArrayException">ArrayException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception-Base.html#t:ArrayException">ArrayException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception-Base.html#t:ArrayException">ArrayException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:ArrayException">ArrayException</a></td><td class="doc empty"> </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-Base.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"> </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-Base.html#t:AssertionFailed">AssertionFailed</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception-Base.html#t:AssertionFailed">AssertionFailed</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:AssertionFailed">AssertionFailed</a></td><td class="doc empty"> </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-Base.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-Base.html#t:AsyncException">AsyncException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Ord.html#t:Ord">Ord</a> <a href="Control-Exception-Base.html#t:AsyncException">AsyncException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception-Base.html#t:AsyncException">AsyncException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception-Base.html#t:AsyncException">AsyncException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:AsyncException">AsyncException</a></td><td class="doc empty"> </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"> </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-Base.html#t:NonTermination">NonTermination</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception-Base.html#t:NonTermination">NonTermination</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:NonTermination">NonTermination</a></td><td class="doc empty"> </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"> </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-Base.html#t:NestedAtomically">NestedAtomically</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception-Base.html#t:NestedAtomically">NestedAtomically</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:NestedAtomically">NestedAtomically</a></td><td class="doc empty"> </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"> </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-Base.html#t:BlockedIndefinitelyOnMVar">BlockedIndefinitelyOnMVar</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception-Base.html#t:BlockedIndefinitelyOnMVar">BlockedIndefinitelyOnMVar</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:BlockedIndefinitelyOnMVar">BlockedIndefinitelyOnMVar</a></td><td class="doc empty"> </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"> </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-Base.html#t:BlockedIndefinitelyOnSTM">BlockedIndefinitelyOnSTM</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception-Base.html#t:BlockedIndefinitelyOnSTM">BlockedIndefinitelyOnSTM</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:BlockedIndefinitelyOnSTM">BlockedIndefinitelyOnSTM</a></td><td class="doc empty"> </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"> </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-Base.html#t:Deadlock">Deadlock</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception-Base.html#t:Deadlock">Deadlock</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:Deadlock">Deadlock</a></td><td class="doc empty"> </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"> </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-Base.html#t:NoMethodError">NoMethodError</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception-Base.html#t:NoMethodError">NoMethodError</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:NoMethodError">NoMethodError</a></td><td class="doc empty"> </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"> </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-Base.html#t:PatternMatchFail">PatternMatchFail</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception-Base.html#t:PatternMatchFail">PatternMatchFail</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:PatternMatchFail">PatternMatchFail</a></td><td class="doc empty"> </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"> </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-Base.html#t:RecConError">RecConError</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception-Base.html#t:RecConError">RecConError</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:RecConError">RecConError</a></td><td class="doc empty"> </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"> </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-Base.html#t:RecSelError">RecSelError</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception-Base.html#t:RecSelError">RecSelError</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:RecSelError">RecSelError</a></td><td class="doc empty"> </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"> </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-Base.html#t:RecUpdError">RecUpdError</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception-Base.html#t:RecUpdError">RecUpdError</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:RecUpdError">RecUpdError</a></td><td class="doc empty"> </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"> </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-Base.html#t:ErrorCall">ErrorCall</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Control-Exception-Base.html#t:ErrorCall">ErrorCall</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Control-Exception-Base.html#t:Exception">Exception</a> <a href="Control-Exception-Base.html#t:ErrorCall">ErrorCall</a></td><td class="doc empty"> </td></tr></table></div></div></div><h1 id="g:2">Throwing exceptions </h1><div class="top"><p class="src"><a name="v:throwIO" class="def">throwIO</a> :: <a href="Control-Exception-Base.html#t:Exception">Exception</a> e => e -> <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>A variant of <code><a href="Control-Exception-Base.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-Base.html#v:throwIO">throwIO</a></code> has a type that is an instance of the type of <code><a href="Control-Exception-Base.html#v:throw">throw</a></code>, the two functions are subtly different: </p><pre> throw e `seq` x ===> throw e throwIO e `seq` x ===> 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-Base.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-Base.html#v:throwIO">throwIO</a></code> variant should be used in preference to <code><a href="Control-Exception-Base.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-Base.html#v:throw">throw</a></code> does not. </p></div></div><div class="top"><p class="src"><a name="v:throw" class="def">throw</a> :: <a href="Control-Exception-Base.html#t:Exception">Exception</a> e => e -> 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:ioError" class="def">ioError</a> :: <a href="System-IO-Error.html#t:IOError">IOError</a> -> <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-Base.html#t:Exception">Exception</a> e => <a href="Control-Concurrent.html#t:ThreadId">ThreadId</a> -> e -> <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-Base.html#v:throwTo">throwTo</a></code> raises an arbitrary exception in the target thread (GHC only). </p><p><code><a href="Control-Exception-Base.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-Base.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-Base.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-Base.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-Base.html#v:throwTo">throwTo</a></code> differs from that described in the paper "Asynchronous exceptions in Haskell" (<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-Base.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-Base.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-Base.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-Base.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-Base.html#v:throwTo">throwTo</a></code>. </p><p>If the target of <code><a href="Control-Exception-Base.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-Base.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-Base.html#v:mask">mask</a></code> or <code><a href="Control-Exception-Base.html#v:uninterruptibleMask">uninterruptibleMask</a></code>. </p></div></div><h1 id="g:3">Catching Exceptions </h1><h2 id="g:4">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-Base.html#t:Exception">Exception</a> e</td><td class="doc empty"> </td></tr><tr><td class="src">=> <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">-> (e -> <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">-> <a href="System-IO.html#t:IO">IO</a> a</td><td class="doc empty"> </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 "handler" 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 -> do let err = show (e :: IOException) hPutStr stderr ("Warning: Couldn't open " ++ f ++ ": " ++ err) return "") </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 "Catching all exceptions" (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-Base.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 "urk") + (1 `div` 0)</code>. Does the expression throw <code>ErrorCall "urk"</code>, or <code>DivideByZero</code>? </p><p>The answer is "it might throw either"; 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 -> (ArithException -> IO Int) -> IO Int</code> then the handler may get run with <code>DivideByZero</code> as an argument, or an <code>ErrorCall "urk"</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-Base.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:catchJust" class="def">catchJust</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="Control-Exception-Base.html#t:Exception">Exception</a> e</td><td class="doc empty"> </td></tr><tr><td class="src">=> (e -> <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">-> <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">-> (b -> <a href="System-IO.html#t:IO">IO</a> a)</td><td class="doc"><p>Handler </p></td></tr><tr><td class="src">-> <a href="System-IO.html#t:IO">IO</a> a</td><td class="doc empty"> </td></tr></table></div><div class="doc"><p>The function <code><a href="Control-Exception-Base.html#v:catchJust">catchJust</a></code> is like <code><a href="Control-Exception-Base.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 -> if isDoesNotExistErrorType (ioeGetErrorType e) then Just () else Nothing) (readFile f) (\_ -> do hPutStrLn stderr ("No such file: " ++ show f) return "") </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-Base.html#v:catch">catch</a></code>, <code><a href="Control-Exception-Base.html#v:catchJust">catchJust</a></code>, etc. </p></div></div><h2 id="g:5">The <code>handle</code> functions </h2><div class="top"><p class="src"><a name="v:handle" class="def">handle</a> :: <a href="Control-Exception-Base.html#t:Exception">Exception</a> e => (e -> <a href="System-IO.html#t:IO">IO</a> a) -> <a href="System-IO.html#t:IO">IO</a> a -> <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>A version of <code><a href="Control-Exception-Base.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 -> exitWith (ExitFailure 1)) $ ... </pre></div></div><div class="top"><p class="src"><a name="v:handleJust" class="def">handleJust</a> :: <a href="Control-Exception-Base.html#t:Exception">Exception</a> e => (e -> <a href="Data-Maybe.html#t:Maybe">Maybe</a> b) -> (b -> <a href="System-IO.html#t:IO">IO</a> a) -> <a href="System-IO.html#t:IO">IO</a> a -> <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>A version of <code><a href="Control-Exception-Base.html#v:catchJust">catchJust</a></code> with the arguments swapped around (see <code><a href="Control-Exception-Base.html#v:handle">handle</a></code>). </p></div></div><h2 id="g:6">The <code>try</code> functions </h2><div class="top"><p class="src"><a name="v:try" class="def">try</a> :: <a href="Control-Exception-Base.html#t:Exception">Exception</a> e => <a href="System-IO.html#t:IO">IO</a> a -> <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-Base.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-Base.html#t:Exception">Exception</a> e => (e -> <a href="Data-Maybe.html#t:Maybe">Maybe</a> b) -> <a href="System-IO.html#t:IO">IO</a> a -> <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-Base.html#v:try">try</a></code> that takes an exception predicate to select which exceptions are caught (c.f. <code><a href="Control-Exception-Base.html#v:catchJust">catchJust</a></code>). If the exception does not match the predicate, it is re-thrown. </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 -> <a href="System-IO.html#t:IO">IO</a> b -> <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>Like <code><a href="Control-Exception-Base.html#v:finally">finally</a></code>, but only performs the final action if there was an exception raised by the computation. </p></div></div><h2 id="g:7">The <code>evaluate</code> function </h2><div class="top"><p class="src"><a name="v:evaluate" class="def">evaluate</a> :: a -> <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 ==> y evaluate x `catch` f ==> (return $! x) `catch` f evaluate x >>= f ==> (return $! x) >>= 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) >>= return </pre></div></div><h2 id="g:8">The <code>mapException</code> function </h2><div class="top"><p class="src"><a name="v:mapException" class="def">mapException</a> :: (<a href="Control-Exception-Base.html#t:Exception">Exception</a> e1, <a href="Control-Exception-Base.html#t:Exception">Exception</a> e2) => (e1 -> e2) -> a -> a</p><div class="doc"><p>This function maps one exception into another as proposed in the paper "A semantics for imprecise exceptions". </p></div></div><h1 id="g:9">Asynchronous Exceptions </h1><h2 id="g:10">Asynchronous exception control </h2><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 -> <a href="System-IO.html#t:IO">IO</a> a) -> <a href="System-IO.html#t:IO">IO</a> b) -> <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-Base.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-Base.html#v:mask">mask</a></code> is to protect the acquisition of a resource: </p><pre> mask $ \restore -> do x <- 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-Base.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-Base.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 -> <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>Like <code><a href="Control-Exception-Base.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 -> <a href="System-IO.html#t:IO">IO</a> a) -> <a href="System-IO.html#t:IO">IO</a> b) -> <a href="System-IO.html#t:IO">IO</a> b</p><div class="doc"><p>Like <code><a href="Control-Exception-Base.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-Base.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 -> <a href="System-IO.html#t:IO">IO</a> a</p><div class="doc"><p>Like <code><a href="Control-Exception-Base.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-Base.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-Base.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-Base.html#t:MaskingState">MaskingState</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Text-Show.html#t:Show">Show</a> <a href="Control-Exception-Base.html#t:MaskingState">MaskingState</a></td><td class="doc empty"> </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-Base.html#t:MaskingState">MaskingState</a></p><div class="doc"><p>Returns the <code><a href="Control-Exception-Base.html#t:MaskingState">MaskingState</a></code> for the current thread. </p></div></div><h2 id="g:11">(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 -> <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-Base.html#v:mask">mask</a></code> instead. </p><p>Applying <code><a href="Control-Exception-Base.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-Base.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 -> <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-Base.html#v:mask">mask</a></code> instead. </p><p>To re-enable asynchronous exceptions inside the scope of <code><a href="Control-Exception-Base.html#v:block">block</a></code>, <code><a href="Control-Exception-Base.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-Base.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><h1 id="g:12">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> -> a -> 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-Base.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-Base.html#v:assert">assert</a></code> is ignored, and the second argument is returned as the result. </p></div></div><h1 id="g:13">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 ("acquire resource") </p></td></tr><tr><td class="src">-> (a -> <a href="System-IO.html#t:IO">IO</a> b)</td><td class="doc"><p>computation to run last ("release resource") </p></td></tr><tr><td class="src">-> (a -> <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">-> <a href="System-IO.html#t:IO">IO</a> c</td><td class="doc empty"> </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-Base.html#v:bracket">bracket</a></code>, because <code><a href="Control-Exception-Base.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-Base.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 "filename" ReadMode) (hClose) (\fileHandle -> do { ... }) </pre><p>The arguments to <code><a href="Control-Exception-Base.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 -> <a href="System-IO.html#t:IO">IO</a> b -> <a href="System-IO.html#t:IO">IO</a> c -> <a href="System-IO.html#t:IO">IO</a> c</p><div class="doc"><p>A variant of <code><a href="Control-Exception-Base.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 ("acquire resource") </p></td></tr><tr><td class="src">-> (a -> <a href="System-IO.html#t:IO">IO</a> b)</td><td class="doc"><p>computation to run last ("release resource") </p></td></tr><tr><td class="src">-> (a -> <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">-> <a href="System-IO.html#t:IO">IO</a> c</td><td class="doc empty"> </td></tr></table></div><div class="doc"><p>Like <code><a href="Control-Exception-Base.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">-> <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">-> <a href="System-IO.html#t:IO">IO</a> a</td><td class="doc empty"> </td></tr></table></div><div class="doc"><p>A specialised variant of <code><a href="Control-Exception-Base.html#v:bracket">bracket</a></code> with just a computation to run afterward. </p></div></div><h1 id="g:14">Calls for GHC runtime </h1><div class="top"><p class="src"><a name="v:recSelError" class="def">recSelError</a> :: <a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:Addr-35-">Addr#</a> -> a</p></div><div class="top"><p class="src"><a name="v:recConError" class="def">recConError</a> :: <a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:Addr-35-">Addr#</a> -> a</p></div><div class="top"><p class="src"><a name="v:irrefutPatError" class="def">irrefutPatError</a> :: <a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:Addr-35-">Addr#</a> -> a</p></div><div class="top"><p class="src"><a name="v:runtimeError" class="def">runtimeError</a> :: <a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:Addr-35-">Addr#</a> -> a</p></div><div class="top"><p class="src"><a name="v:nonExhaustiveGuardsError" class="def">nonExhaustiveGuardsError</a> :: <a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:Addr-35-">Addr#</a> -> a</p></div><div class="top"><p class="src"><a name="v:patError" class="def">patError</a> :: <a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:Addr-35-">Addr#</a> -> a</p></div><div class="top"><p class="src"><a name="v:noMethodBindingError" class="def">noMethodBindingError</a> :: <a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:Addr-35-">Addr#</a> -> a</p></div><div class="top"><p class="src"><a name="v:absentError" class="def">absentError</a> :: <a href="../ghc-prim-0.2.0.0/GHC-Prim.html#t:Addr-35-">Addr#</a> -> a</p></div><div class="top"><p class="src"><a name="v:nonTermination" class="def">nonTermination</a> :: <a href="Control-Exception-Base.html#t:SomeException">SomeException</a></p></div><div class="top"><p class="src"><a name="v:nestedAtomically" class="def">nestedAtomically</a> :: <a href="Control-Exception-Base.html#t:SomeException">SomeException</a></p></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>