<!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>System.IO.Error</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_System-IO-Error.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">haskell2010-1.1.0.1: Compatibility with Haskell 2010</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Safe Haskell</th><td>Safe</td></tr></table><p class="caption">System.IO.Error</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">I/O errors </a><ul><li><a href="#g:2">Classifying I/O errors </a></li><li><a href="#g:3">Attributes of I/O errors </a></li></ul></li><li><a href="#g:4">Types of I/O error </a></li><li><a href="#g:5">Throwing and catching I/O errors </a></li></ul></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">type</span> <a href="#t:IOError">IOError</a> = <a href="Prelude.html#t:IOError">IOError</a></li><li class="src short"><a href="#v:userError">userError</a> :: <a href="Prelude.html#t:String">String</a> -> <a href="Prelude.html#t:IOError">IOError</a></li><li class="src short"><a href="#v:mkIOError">mkIOError</a> :: <a href="System-IO-Error.html#t:IOErrorType">IOErrorType</a> -> <a href="Prelude.html#t:String">String</a> -> <a href="Prelude.html#t:Maybe">Maybe</a> <a href="System-IO.html#t:Handle">Handle</a> -> <a href="Prelude.html#t:Maybe">Maybe</a> <a href="Prelude.html#t:FilePath">FilePath</a> -> <a href="Prelude.html#t:IOError">IOError</a></li><li class="src short"><a href="#v:annotateIOError">annotateIOError</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:String">String</a> -> <a href="Prelude.html#t:Maybe">Maybe</a> <a href="System-IO.html#t:Handle">Handle</a> -> <a href="Prelude.html#t:Maybe">Maybe</a> <a href="Prelude.html#t:FilePath">FilePath</a> -> <a href="Prelude.html#t:IOError">IOError</a></li><li class="src short"><a href="#v:isAlreadyExistsError">isAlreadyExistsError</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:isDoesNotExistError">isDoesNotExistError</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:isAlreadyInUseError">isAlreadyInUseError</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:isFullError">isFullError</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:isEOFError">isEOFError</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:isIllegalOperation">isIllegalOperation</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:isPermissionError">isPermissionError</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:isUserError">isUserError</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:ioeGetErrorString">ioeGetErrorString</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:String">String</a></li><li class="src short"><a href="#v:ioeGetHandle">ioeGetHandle</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Maybe">Maybe</a> <a href="System-IO.html#t:Handle">Handle</a></li><li class="src short"><a href="#v:ioeGetFileName">ioeGetFileName</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Maybe">Maybe</a> <a href="Prelude.html#t:FilePath">FilePath</a></li><li class="src short"><span class="keyword">data</span> <a href="#t:IOErrorType">IOErrorType</a> </li><li class="src short"><a href="#v:alreadyExistsErrorType">alreadyExistsErrorType</a> :: <a href="System-IO-Error.html#t:IOErrorType">IOErrorType</a></li><li class="src short"><a href="#v:doesNotExistErrorType">doesNotExistErrorType</a> :: <a href="System-IO-Error.html#t:IOErrorType">IOErrorType</a></li><li class="src short"><a href="#v:alreadyInUseErrorType">alreadyInUseErrorType</a> :: <a href="System-IO-Error.html#t:IOErrorType">IOErrorType</a></li><li class="src short"><a href="#v:fullErrorType">fullErrorType</a> :: <a href="System-IO-Error.html#t:IOErrorType">IOErrorType</a></li><li class="src short"><a href="#v:eofErrorType">eofErrorType</a> :: <a href="System-IO-Error.html#t:IOErrorType">IOErrorType</a></li><li class="src short"><a href="#v:illegalOperationErrorType">illegalOperationErrorType</a> :: <a href="System-IO-Error.html#t:IOErrorType">IOErrorType</a></li><li class="src short"><a href="#v:permissionErrorType">permissionErrorType</a> :: <a href="System-IO-Error.html#t:IOErrorType">IOErrorType</a></li><li class="src short"><a href="#v:userErrorType">userErrorType</a> :: <a href="System-IO-Error.html#t:IOErrorType">IOErrorType</a></li><li class="src short"><a href="#v:ioError">ioError</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:catch">catch</a> :: <a href="Prelude.html#t:IO">IO</a> a -> (<a href="System-IO-Error.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:IO">IO</a> a) -> <a href="Prelude.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:try">try</a> :: <a href="Prelude.html#t:IO">IO</a> a -> <a href="Prelude.html#t:IO">IO</a> (<a href="Prelude.html#t:Either">Either</a> <a href="System-IO-Error.html#t:IOError">IOError</a> a)</li></ul></div><div id="interface"><h1 id="g:1">I/O errors </h1><div class="top"><p class="src"><span class="keyword">type</span> <a name="t:IOError" class="def">IOError</a> = <a href="Prelude.html#t:IOError">IOError</a></p><div class="doc"><p>Errors of type <code><a href="System-IO-Error.html#t:IOError">IOError</a></code> are used by the <code><a href="Prelude.html#t:IO">IO</a></code> monad. This is an abstract type; the module <a href="../base-4.5.1.0/System-IO-Error.html">System.IO.Error</a> provides functions to interrogate and construct values of type <code><a href="System-IO-Error.html#t:IOError">IOError</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:userError" class="def">userError</a> :: <a href="Prelude.html#t:String">String</a> -> <a href="Prelude.html#t:IOError">IOError</a><a href="../base-4.5.1.0/src/GHC-IO-Exception.html#userError" class="link">Source</a></p><div class="doc"><p>Construct an <code><a href="Prelude.html#t:IOError">IOError</a></code> value with a string describing the error. The <code><a href="Prelude.html#v:fail">fail</a></code> method of the <code><a href="Prelude.html#t:IO">IO</a></code> instance of the <code><a href="Prelude.html#t:Monad">Monad</a></code> class raises a <code><a href="System-IO-Error.html#v:userError">userError</a></code>, thus: </p><pre> instance Monad IO where ... fail s = ioError (userError s) </pre></div></div><div class="top"><p class="src"><a name="v:mkIOError" class="def">mkIOError</a> :: <a href="System-IO-Error.html#t:IOErrorType">IOErrorType</a> -> <a href="Prelude.html#t:String">String</a> -> <a href="Prelude.html#t:Maybe">Maybe</a> <a href="System-IO.html#t:Handle">Handle</a> -> <a href="Prelude.html#t:Maybe">Maybe</a> <a href="Prelude.html#t:FilePath">FilePath</a> -> <a href="Prelude.html#t:IOError">IOError</a><a href="../base-4.5.1.0/src/System-IO-Error.html#mkIOError" class="link">Source</a></p><div class="doc"><p>Construct an <code><a href="Prelude.html#t:IOError">IOError</a></code> of the given type where the second argument describes the error location and the third and fourth argument contain the file handle and file path of the file involved in the error if applicable. </p></div></div><div class="top"><p class="src"><a name="v:annotateIOError" class="def">annotateIOError</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:String">String</a> -> <a href="Prelude.html#t:Maybe">Maybe</a> <a href="System-IO.html#t:Handle">Handle</a> -> <a href="Prelude.html#t:Maybe">Maybe</a> <a href="Prelude.html#t:FilePath">FilePath</a> -> <a href="Prelude.html#t:IOError">IOError</a><a href="../base-4.5.1.0/src/System-IO-Error.html#annotateIOError" class="link">Source</a></p><div class="doc"><p>Adds a location description and maybe a file path and file handle to an <code><a href="Prelude.html#t:IOError">IOError</a></code>. If any of the file handle or file path is not given the corresponding value in the <code><a href="Prelude.html#t:IOError">IOError</a></code> remains unaltered. </p></div></div><h2 id="g:2">Classifying I/O errors </h2><div class="top"><p class="src"><a name="v:isAlreadyExistsError" class="def">isAlreadyExistsError</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/System-IO-Error.html#isAlreadyExistsError" class="link">Source</a></p><div class="doc"><p>An error indicating that an <code><a href="Prelude.html#t:IO">IO</a></code> operation failed because one of its arguments already exists. </p></div></div><div class="top"><p class="src"><a name="v:isDoesNotExistError" class="def">isDoesNotExistError</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/System-IO-Error.html#isDoesNotExistError" class="link">Source</a></p><div class="doc"><p>An error indicating that an <code><a href="Prelude.html#t:IO">IO</a></code> operation failed because one of its arguments does not exist. </p></div></div><div class="top"><p class="src"><a name="v:isAlreadyInUseError" class="def">isAlreadyInUseError</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/System-IO-Error.html#isAlreadyInUseError" class="link">Source</a></p><div class="doc"><p>An error indicating that an <code><a href="Prelude.html#t:IO">IO</a></code> operation failed because one of its arguments is a single-use resource, which is already being used (for example, opening the same file twice for writing might give this error). </p></div></div><div class="top"><p class="src"><a name="v:isFullError" class="def">isFullError</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/System-IO-Error.html#isFullError" class="link">Source</a></p><div class="doc"><p>An error indicating that an <code><a href="Prelude.html#t:IO">IO</a></code> operation failed because the device is full. </p></div></div><div class="top"><p class="src"><a name="v:isEOFError" class="def">isEOFError</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/System-IO-Error.html#isEOFError" class="link">Source</a></p><div class="doc"><p>An error indicating that an <code><a href="Prelude.html#t:IO">IO</a></code> operation failed because the end of file has been reached. </p></div></div><div class="top"><p class="src"><a name="v:isIllegalOperation" class="def">isIllegalOperation</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/System-IO-Error.html#isIllegalOperation" class="link">Source</a></p><div class="doc"><p>An error indicating that an <code><a href="Prelude.html#t:IO">IO</a></code> operation failed because the operation was not possible. Any computation which returns an <code><a href="Prelude.html#t:IO">IO</a></code> result may fail with <code><a href="System-IO-Error.html#v:isIllegalOperation">isIllegalOperation</a></code>. In some cases, an implementation will not be able to distinguish between the possible error causes. In this case it should fail with <code><a href="System-IO-Error.html#v:isIllegalOperation">isIllegalOperation</a></code>. </p></div></div><div class="top"><p class="src"><a name="v:isPermissionError" class="def">isPermissionError</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/System-IO-Error.html#isPermissionError" class="link">Source</a></p><div class="doc"><p>An error indicating that an <code><a href="Prelude.html#t:IO">IO</a></code> operation failed because the user does not have sufficient operating system privilege to perform that operation. </p></div></div><div class="top"><p class="src"><a name="v:isUserError" class="def">isUserError</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Bool">Bool</a><a href="../base-4.5.1.0/src/System-IO-Error.html#isUserError" class="link">Source</a></p><div class="doc"><p>A programmer-defined error value constructed using <code><a href="System-IO-Error.html#v:userError">userError</a></code>. </p></div></div><h2 id="g:3">Attributes of I/O errors </h2><div class="top"><p class="src"><a name="v:ioeGetErrorString" class="def">ioeGetErrorString</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:String">String</a><a href="../base-4.5.1.0/src/System-IO-Error.html#ioeGetErrorString" class="link">Source</a></p></div><div class="top"><p class="src"><a name="v:ioeGetHandle" class="def">ioeGetHandle</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Maybe">Maybe</a> <a href="System-IO.html#t:Handle">Handle</a><a href="../base-4.5.1.0/src/System-IO-Error.html#ioeGetHandle" class="link">Source</a></p></div><div class="top"><p class="src"><a name="v:ioeGetFileName" class="def">ioeGetFileName</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:Maybe">Maybe</a> <a href="Prelude.html#t:FilePath">FilePath</a><a href="../base-4.5.1.0/src/System-IO-Error.html#ioeGetFileName" class="link">Source</a></p></div><h1 id="g:4">Types of I/O error </h1><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:IOErrorType" class="def">IOErrorType</a> <a href="../base-4.5.1.0/src/GHC-IO-Exception.html#IOErrorType" class="link">Source</a></p><div class="doc"><p>An abstract type that contains a value for each variant of <code><a href="Prelude.html#t:IOError">IOError</a></code>. </p></div><div class="subs instances"><p id="control.i:IOErrorType" class="caption collapser" onclick="toggleSection('i:IOErrorType')">Instances</p><div id="section.i:IOErrorType" class="show"><table><tr><td class="src"><a href="Prelude.html#t:Eq">Eq</a> <a href="System-IO-Error.html#t:IOErrorType">IOErrorType</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="Prelude.html#t:Show">Show</a> <a href="System-IO-Error.html#t:IOErrorType">IOErrorType</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:alreadyExistsErrorType" class="def">alreadyExistsErrorType</a> :: <a href="System-IO-Error.html#t:IOErrorType">IOErrorType</a><a href="../base-4.5.1.0/src/System-IO-Error.html#alreadyExistsErrorType" class="link">Source</a></p><div class="doc"><p>I/O error where the operation failed because one of its arguments already exists. </p></div></div><div class="top"><p class="src"><a name="v:doesNotExistErrorType" class="def">doesNotExistErrorType</a> :: <a href="System-IO-Error.html#t:IOErrorType">IOErrorType</a><a href="../base-4.5.1.0/src/System-IO-Error.html#doesNotExistErrorType" class="link">Source</a></p><div class="doc"><p>I/O error where the operation failed because one of its arguments does not exist. </p></div></div><div class="top"><p class="src"><a name="v:alreadyInUseErrorType" class="def">alreadyInUseErrorType</a> :: <a href="System-IO-Error.html#t:IOErrorType">IOErrorType</a><a href="../base-4.5.1.0/src/System-IO-Error.html#alreadyInUseErrorType" class="link">Source</a></p><div class="doc"><p>I/O error where the operation failed because one of its arguments is a single-use resource, which is already being used. </p></div></div><div class="top"><p class="src"><a name="v:fullErrorType" class="def">fullErrorType</a> :: <a href="System-IO-Error.html#t:IOErrorType">IOErrorType</a><a href="../base-4.5.1.0/src/System-IO-Error.html#fullErrorType" class="link">Source</a></p><div class="doc"><p>I/O error where the operation failed because the device is full. </p></div></div><div class="top"><p class="src"><a name="v:eofErrorType" class="def">eofErrorType</a> :: <a href="System-IO-Error.html#t:IOErrorType">IOErrorType</a><a href="../base-4.5.1.0/src/System-IO-Error.html#eofErrorType" class="link">Source</a></p><div class="doc"><p>I/O error where the operation failed because the end of file has been reached. </p></div></div><div class="top"><p class="src"><a name="v:illegalOperationErrorType" class="def">illegalOperationErrorType</a> :: <a href="System-IO-Error.html#t:IOErrorType">IOErrorType</a><a href="../base-4.5.1.0/src/System-IO-Error.html#illegalOperationErrorType" class="link">Source</a></p><div class="doc"><p>I/O error where the operation is not possible. </p></div></div><div class="top"><p class="src"><a name="v:permissionErrorType" class="def">permissionErrorType</a> :: <a href="System-IO-Error.html#t:IOErrorType">IOErrorType</a><a href="../base-4.5.1.0/src/System-IO-Error.html#permissionErrorType" class="link">Source</a></p><div class="doc"><p>I/O error where the operation failed because the user does not have sufficient operating system privilege to perform that operation. </p></div></div><div class="top"><p class="src"><a name="v:userErrorType" class="def">userErrorType</a> :: <a href="System-IO-Error.html#t:IOErrorType">IOErrorType</a><a href="../base-4.5.1.0/src/System-IO-Error.html#userErrorType" class="link">Source</a></p><div class="doc"><p>I/O error that is programmer-defined. </p></div></div><h1 id="g:5">Throwing and catching I/O errors </h1><div class="top"><p class="src"><a name="v:ioError" class="def">ioError</a> :: <a href="Prelude.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:IO">IO</a> a<a href="../base-4.5.1.0/src/GHC-IO-Exception.html#ioError" class="link">Source</a></p><div class="doc"><p>Raise an <code><a href="Prelude.html#t:IOError">IOError</a></code> in the <code><a href="Prelude.html#t:IO">IO</a></code> monad. </p></div></div><div class="top"><p class="src"><a name="v:catch" class="def">catch</a> :: <a href="Prelude.html#t:IO">IO</a> a -> (<a href="System-IO-Error.html#t:IOError">IOError</a> -> <a href="Prelude.html#t:IO">IO</a> a) -> <a href="Prelude.html#t:IO">IO</a> a</p><div class="doc"><p>The <code><a href="System-IO-Error.html#v:catch">catch</a></code> function establishes a handler that receives any <code><a href="System-IO-Error.html#t:IOError">IOError</a></code> raised in the action protected by <code><a href="System-IO-Error.html#v:catch">catch</a></code>. An <code><a href="System-IO-Error.html#t:IOError">IOError</a></code> is caught by the most recent handler established by <code><a href="System-IO-Error.html#v:catch">catch</a></code>. These handlers are not selective: all <code><a href="System-IO-Error.html#t:IOError">IOError</a></code>s are caught. Exception propagation must be explicitly provided in a handler by re-raising any unwanted exceptions. For example, in </p><pre> f = catch g (\e -> if IO.isEOFError e then return [] else ioError e) </pre><p>the function <code>f</code> returns <code>[]</code> when an end-of-file exception (cf. <code><a href="System-IO-Error.html#v:isEOFError">isEOFError</a></code>) occurs in <code>g</code>; otherwise, the exception is propagated to the next outer handler. </p><p>When an exception propagates outside the main program, the Haskell system prints the associated <code><a href="System-IO-Error.html#t:IOError">IOError</a></code> value and exits the program. </p></div></div><div class="top"><p class="src"><a name="v:try" class="def">try</a> :: <a href="Prelude.html#t:IO">IO</a> a -> <a href="Prelude.html#t:IO">IO</a> (<a href="Prelude.html#t:Either">Either</a> <a href="System-IO-Error.html#t:IOError">IOError</a> a)</p><div class="doc"><p>The construct <code><a href="System-IO-Error.html#v:try">try</a></code> <code>comp</code> exposes IO errors which occur within a computation, and which are not fully handled. </p></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.11.0</p></div></body></html>