<!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>Panic</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_Panic.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">ghc-7.4.2: The GHC API</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Safe Haskell</th><td>None</td></tr></table><p class="caption">Panic</p></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:GhcException">GhcException</a> <ul class="subs"><li>= <a href="#v:PhaseFailed">PhaseFailed</a> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> <a href="../base-4.5.1.0/System-Exit.html#t:ExitCode">ExitCode</a> </li><li>| <a href="#v:Signal">Signal</a> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a> </li><li>| <a href="#v:UsageError">UsageError</a> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> </li><li>| <a href="#v:CmdLineError">CmdLineError</a> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> </li><li>| <a href="#v:Panic">Panic</a> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> </li><li>| <a href="#v:Sorry">Sorry</a> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> </li><li>| <a href="#v:InstallationError">InstallationError</a> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> </li><li>| <a href="#v:ProgramError">ProgramError</a> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> </li></ul></li><li class="src short"><a href="#v:showGhcException">showGhcException</a> :: <a href="Panic.html#t:GhcException">GhcException</a> -> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a></li><li class="src short"><a href="#v:throwGhcException">throwGhcException</a> :: <a href="Panic.html#t:GhcException">GhcException</a> -> a</li><li class="src short"><a href="#v:handleGhcException">handleGhcException</a> :: <a href="Exception.html#t:ExceptionMonad">ExceptionMonad</a> m => (<a href="Panic.html#t:GhcException">GhcException</a> -> m a) -> m a -> m a</li><li class="src short"><a href="#v:ghcError">ghcError</a> :: <a href="Panic.html#t:GhcException">GhcException</a> -> a</li><li class="src short"><a href="#v:progName">progName</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a></li><li class="src short"><a href="#v:pgmError">pgmError</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> a</li><li class="src short"><a href="#v:panic">panic</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> a</li><li class="src short"><a href="#v:sorry">sorry</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> a</li><li class="src short"><a href="#v:panicFastInt">panicFastInt</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> <a href="FastTypes.html#t:FastInt">FastInt</a></li><li class="src short"><a href="#v:assertPanic">assertPanic</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a> -> a</li><li class="src short"><a href="#v:trace">trace</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> a -> a</li><li class="src short"><span class="keyword">class</span> (<a href="../base-4.5.1.0/Data-Typeable-Internal.html#t:Typeable">Typeable</a> e, <a href="../base-4.5.1.0/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="../base-4.5.1.0/Control-Exception-Base.html#t:SomeException">SomeException</a></li><li><a href="#v:fromException">fromException</a> :: <a href="../base-4.5.1.0/Control-Exception-Base.html#t:SomeException">SomeException</a> -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> e</li></ul></li><li class="src short"><a href="#v:showException">showException</a> :: <a href="Panic.html#t:Exception">Exception</a> e => e -> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a></li><li class="src short"><a href="#v:safeShowException">safeShowException</a> :: <a href="Panic.html#t:Exception">Exception</a> e => e -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a></li><li class="src short"><a href="#v:try">try</a> :: <a href="Panic.html#t:Exception">Exception</a> e => <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> a -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> (<a href="../base-4.5.1.0/Data-Either.html#t:Either">Either</a> e a)</li><li class="src short"><a href="#v:tryMost">tryMost</a> :: <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> a -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> (<a href="../base-4.5.1.0/Data-Either.html#t:Either">Either</a> <a href="../base-4.5.1.0/Control-Exception-Base.html#t:SomeException">SomeException</a> a)</li><li class="src short"><a href="#v:throwTo">throwTo</a> :: <a href="Panic.html#t:Exception">Exception</a> e => <a href="../base-4.5.1.0/Control-Concurrent.html#t:ThreadId">ThreadId</a> -> e -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:installSignalHandlers">installSignalHandlers</a> :: <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:interruptTargetThread">interruptTargetThread</a> :: <a href="../base-4.5.1.0/Control-Concurrent-MVar.html#t:MVar">MVar</a> [<a href="../base-4.5.1.0/Control-Concurrent.html#t:ThreadId">ThreadId</a>]</li></ul></div><div id="interface"><h1>Documentation</h1><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:GhcException" class="def">GhcException</a> </p><div class="doc"><p>GHC's own exception type error messages all take the form: </p><pre> <a href="location">location</a>: <a href="error">error</a> </pre><p>If the location is on the command line, or in GHC itself, then <a href="location">location</a>=<a href="ghc.html">ghc</a>. All of the error types below correspond to a <a href="location">location</a> of <a href="ghc.html">ghc</a>, except for ProgramError (where the string is assumed to contain a location already, so we don't print one). </p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:PhaseFailed" class="def">PhaseFailed</a> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> <a href="../base-4.5.1.0/System-Exit.html#t:ExitCode">ExitCode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a name="v:Signal" class="def">Signal</a> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a></td><td class="doc"><p>Some other fatal signal (SIGHUP,SIGTERM) </p></td></tr><tr><td class="src"><a name="v:UsageError" class="def">UsageError</a> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a></td><td class="doc"><p>Prints the short usage msg after the error </p></td></tr><tr><td class="src"><a name="v:CmdLineError" class="def">CmdLineError</a> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a></td><td class="doc"><p>A problem with the command line arguments, but don't print usage. </p></td></tr><tr><td class="src"><a name="v:Panic" class="def">Panic</a> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a></td><td class="doc"><p>The <code>impossible</code> happened. </p></td></tr><tr><td class="src"><a name="v:Sorry" class="def">Sorry</a> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a></td><td class="doc"><p>The user tickled something that's known not to work yet, but we're not counting it as a bug. </p></td></tr><tr><td class="src"><a name="v:InstallationError" class="def">InstallationError</a> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a></td><td class="doc"><p>An installation problem. </p></td></tr><tr><td class="src"><a name="v:ProgramError" class="def">ProgramError</a> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a></td><td class="doc"><p>An error in the user's code, probably. </p></td></tr></table></div><div class="subs instances"><p id="control.i:GhcException" class="caption collapser" onclick="toggleSection('i:GhcException')">Instances</p><div id="section.i:GhcException" class="show"><table><tr><td class="src"><a href="../base-4.5.1.0/Data-Eq.html#t:Eq">Eq</a> <a href="Panic.html#t:GhcException">GhcException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="../base-4.5.1.0/Text-Show.html#t:Show">Show</a> <a href="Panic.html#t:GhcException">GhcException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="../base-4.5.1.0/Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="Panic.html#t:GhcException">GhcException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="Panic.html#t:GhcException">GhcException</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:showGhcException" class="def">showGhcException</a> :: <a href="Panic.html#t:GhcException">GhcException</a> -> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a></p><div class="doc"><p>Append a description of the given exception to this string. </p></div></div><div class="top"><p class="src"><a name="v:throwGhcException" class="def">throwGhcException</a> :: <a href="Panic.html#t:GhcException">GhcException</a> -> a</p></div><div class="top"><p class="src"><a name="v:handleGhcException" class="def">handleGhcException</a> :: <a href="Exception.html#t:ExceptionMonad">ExceptionMonad</a> m => (<a href="Panic.html#t:GhcException">GhcException</a> -> m a) -> m a -> m a</p></div><div class="top"><p class="src"><a name="v:ghcError" class="def">ghcError</a> :: <a href="Panic.html#t:GhcException">GhcException</a> -> a</p><div class="doc"><p>Alias for <code><a href="Panic.html#v:throwGhcException">throwGhcException</a></code> </p></div></div><div class="top"><p class="src"><a name="v:progName" class="def">progName</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a></p><div class="doc"><p>The name of this GHC. </p></div></div><div class="top"><p class="src"><a name="v:pgmError" class="def">pgmError</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> a</p><div class="doc"><p>Panics and asserts. </p></div></div><div class="top"><p class="src"><a name="v:panic" class="def">panic</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> a</p><div class="doc"><p>Panics and asserts. </p></div></div><div class="top"><p class="src"><a name="v:sorry" class="def">sorry</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> a</p><div class="doc"><p>Panics and asserts. </p></div></div><div class="top"><p class="src"><a name="v:panicFastInt" class="def">panicFastInt</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> <a href="FastTypes.html#t:FastInt">FastInt</a></p><div class="doc"><p>Panic while pretending to return an unboxed int. You can't use the regular panic functions in expressions producing unboxed ints because they have the wrong kind. </p></div></div><div class="top"><p class="src"><a name="v:assertPanic" class="def">assertPanic</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> <a href="../base-4.5.1.0/Data-Int.html#t:Int">Int</a> -> a</p><div class="doc"><p>Throw an failed assertion exception for a given filename and line number. </p></div></div><div class="top"><p class="src"><a name="v:trace" class="def">trace</a> :: <a href="../base-4.5.1.0/Data-String.html#t:String">String</a> -> a -> a<a href="../base-4.5.1.0/src/Debug-Trace.html#trace" class="link">Source</a></p><div class="doc"><p>The <code><a href="Panic.html#v:trace">trace</a></code> function outputs the trace message given as its first argument, before returning the second argument as its result. </p><p>For example, this returns the value of <code>f x</code> but first outputs the message. </p><pre> trace ("calling f with x = " ++ show x) (f x) </pre><p>The <code><a href="Panic.html#v:trace">trace</a></code> function should <em>only</em> be used for debugging, or for monitoring execution. The function is not referentially transparent: its type indicates that it is a pure function but it has the side effect of outputting the trace message. </p></div></div><div class="top"><p class="src"><span class="keyword">class</span> (<a href="../base-4.5.1.0/Data-Typeable-Internal.html#t:Typeable">Typeable</a> e, <a href="../base-4.5.1.0/Text-Show.html#t:Show">Show</a> e) => <a name="t:Exception" class="def">Exception</a> e <span class="keyword">where</span><a href="../base-4.5.1.0/src/GHC-Exception.html#Exception" class="link">Source</a></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="../base-4.5.1.0/Control-Exception-Base.html#t:SomeException">SomeException</a><a href="../base-4.5.1.0/src/GHC-Exception.html#toException" class="link">Source</a></p><p class="src"><a name="v:fromException" class="def">fromException</a> :: <a href="../base-4.5.1.0/Control-Exception-Base.html#t:SomeException">SomeException</a> -> <a href="../base-4.5.1.0/Data-Maybe.html#t:Maybe">Maybe</a> e<a href="../base-4.5.1.0/src/GHC-Exception.html#fromException" class="link">Source</a></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="Panic.html#t:Exception">Exception</a> <a href="../base-4.5.1.0/Control-Exception-Base.html#t:IOException">IOException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="../base-4.5.1.0/Control-Exception-Base.html#t:PatternMatchFail">PatternMatchFail</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="../base-4.5.1.0/Control-Exception-Base.html#t:RecSelError">RecSelError</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="../base-4.5.1.0/Control-Exception-Base.html#t:RecConError">RecConError</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="../base-4.5.1.0/Control-Exception-Base.html#t:RecUpdError">RecUpdError</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="../base-4.5.1.0/Control-Exception-Base.html#t:NoMethodError">NoMethodError</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="../base-4.5.1.0/Control-Exception-Base.html#t:NonTermination">NonTermination</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="../base-4.5.1.0/Control-Exception-Base.html#t:NestedAtomically">NestedAtomically</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="../base-4.5.1.0/Control-Exception-Base.html#t:BlockedIndefinitelyOnMVar">BlockedIndefinitelyOnMVar</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="../base-4.5.1.0/Control-Exception-Base.html#t:BlockedIndefinitelyOnSTM">BlockedIndefinitelyOnSTM</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="../base-4.5.1.0/Control-Exception-Base.html#t:Deadlock">Deadlock</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="../base-4.5.1.0/Control-Exception-Base.html#t:AssertionFailed">AssertionFailed</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="../base-4.5.1.0/Control-Exception-Base.html#t:AsyncException">AsyncException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="../base-4.5.1.0/Control-Exception-Base.html#t:ArrayException">ArrayException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="../base-4.5.1.0/System-Exit.html#t:ExitCode">ExitCode</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="../base-4.5.1.0/Data-Dynamic.html#t:Dynamic">Dynamic</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="../base-4.5.1.0/Control-Exception-Base.html#t:SomeException">SomeException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="../base-4.5.1.0/Control-Exception-Base.html#t:ErrorCall">ErrorCall</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="../base-4.5.1.0/Control-Exception-Base.html#t:ArithException">ArithException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="Panic.html#t:GhcException">GhcException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="IOEnv.html#t:IOEnvFailure">IOEnvFailure</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="HscTypes.html#t:GhcApiError">GhcApiError</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Panic.html#t:Exception">Exception</a> <a href="HscTypes.html#t:SourceError">SourceError</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:showException" class="def">showException</a> :: <a href="Panic.html#t:Exception">Exception</a> e => e -> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a></p><div class="doc"><p>Show an exception as a string. </p></div></div><div class="top"><p class="src"><a name="v:safeShowException" class="def">safeShowException</a> :: <a href="Panic.html#t:Exception">Exception</a> e => e -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> <a href="../base-4.5.1.0/Data-String.html#t:String">String</a></p><div class="doc"><p>Show an exception which can possibly throw other exceptions. Used when displaying exception thrown within TH code. </p></div></div><div class="top"><p class="src"><a name="v:try" class="def">try</a> :: <a href="Panic.html#t:Exception">Exception</a> e => <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> a -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> (<a href="../base-4.5.1.0/Data-Either.html#t:Either">Either</a> e a)<a href="../base-4.5.1.0/src/Control-Exception-Base.html#try" class="link">Source</a></p><div class="doc"><p>Similar to <code><a href="../base-4.5.1.0/Control-Exception-Base.html#v:catch">catch</a></code>, but returns an <code><a href="../base-4.5.1.0/Data-Either.html#t:Either">Either</a></code> result which is <code>(<code><a href="../base-4.5.1.0/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="../base-4.5.1.0/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="../base-4.5.1.0/System-IO-Error.html">System.IO.Error</a> also exports a function called <code><a href="../base-4.5.1.0/System-IO-Error.html#v:try">try</a></code> with a similar type to <code><a href="../base-4.5.1.0/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:tryMost" class="def">tryMost</a> :: <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> a -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> (<a href="../base-4.5.1.0/Data-Either.html#t:Either">Either</a> <a href="../base-4.5.1.0/Control-Exception-Base.html#t:SomeException">SomeException</a> a)</p><div class="doc"><p>Like try, but pass through UserInterrupt and Panic exceptions. Used when we want soft failures when reading interface files, for example. TODO: I'm not entirely sure if this is catching what we really want to catch </p></div></div><div class="top"><p class="src"><a name="v:throwTo" class="def">throwTo</a> :: <a href="Panic.html#t:Exception">Exception</a> e => <a href="../base-4.5.1.0/Control-Concurrent.html#t:ThreadId">ThreadId</a> -> e -> <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> ()<a href="../base-4.5.1.0/src/GHC-Conc-Sync.html#throwTo" class="link">Source</a></p><div class="doc"><p><code><a href="Panic.html#v:throwTo">throwTo</a></code> raises an arbitrary exception in the target thread (GHC only). </p><p><code><a href="Panic.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="Panic.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="../base-4.5.1.0/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="Panic.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="Panic.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="Panic.html#v:throwTo">throwTo</a></code> is non-blocking; but the library implementation adopts a more synchronous design in which <code><a href="Panic.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="Panic.html#v:throwTo">throwTo</a></code> is therefore interruptible (see Section 5.3 of the paper). Unlike other interruptible operations, however, <code><a href="Panic.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="Panic.html#v:throwTo">throwTo</a></code>. </p><p>If the target of <code><a href="Panic.html#v:throwTo">throwTo</a></code> is the calling thread, then the behaviour is the same as <code><a href="../base-4.5.1.0/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="../base-4.5.1.0/System-IO-Unsafe.html#v:unsafePerformIO">unsafePerformIO</a></code> or <code><a href="../base-4.5.1.0/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="Panic.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="../base-4.5.1.0/Control-Exception-Base.html#v:mask">mask</a></code> or <code><a href="../base-4.5.1.0/Control-Exception-Base.html#v:uninterruptibleMask">uninterruptibleMask</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:installSignalHandlers" class="def">installSignalHandlers</a> :: <a href="../base-4.5.1.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Install standard signal handlers for catching ^C, which just throw an exception in the target thread. The current target thread is the thread at the head of the list in the MVar passed to installSignalHandlers. </p></div></div><div class="top"><p class="src"><a name="v:interruptTargetThread" class="def">interruptTargetThread</a> :: <a href="../base-4.5.1.0/Control-Concurrent-MVar.html#t:MVar">MVar</a> [<a href="../base-4.5.1.0/Control-Concurrent.html#t:ThreadId">ThreadId</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>