~ubuntu-branches/ubuntu/precise/ghc/precise

« back to all changes in this revision

Viewing changes to libraries/haskell2010/System/IO/Error.hs

  • Committer: Bazaar Package Importer
  • Author(s): Joachim Breitner
  • Date: 2011-01-17 12:49:24 UTC
  • Revision ID: james.westby@ubuntu.com-20110117124924-do1pym1jlf5o636m
Tags: upstream-7.0.1
ImportĀ upstreamĀ versionĀ 7.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
 
2
-- apparent bug in GHC, reports a bogus warning for the Prelude import below
 
3
module System.IO.Error (
 
4
      -- * I\/O errors
 
5
    IOError,                    -- = IOException
 
6
 
 
7
    userError,                  -- :: String  -> IOError
 
8
 
 
9
    mkIOError,                  -- :: IOErrorType -> String -> Maybe Handle
 
10
                                --    -> Maybe FilePath -> IOError
 
11
 
 
12
    annotateIOError,            -- :: IOError -> String -> Maybe Handle
 
13
                                --    -> Maybe FilePath -> IOError
 
14
 
 
15
    -- ** Classifying I\/O errors
 
16
    isAlreadyExistsError,       -- :: IOError -> Bool
 
17
    isDoesNotExistError,
 
18
    isAlreadyInUseError,
 
19
    isFullError, 
 
20
    isEOFError,
 
21
    isIllegalOperation, 
 
22
    isPermissionError,
 
23
    isUserError,
 
24
 
 
25
    -- ** Attributes of I\/O errors
 
26
    ioeGetErrorString,          -- :: IOError -> String
 
27
    ioeGetHandle,               -- :: IOError -> Maybe Handle
 
28
    ioeGetFileName,             -- :: IOError -> Maybe FilePath
 
29
 
 
30
    -- * Types of I\/O error
 
31
    IOErrorType,                -- abstract
 
32
 
 
33
    alreadyExistsErrorType,     -- :: IOErrorType
 
34
    doesNotExistErrorType,
 
35
    alreadyInUseErrorType,
 
36
    fullErrorType,
 
37
    eofErrorType,
 
38
    illegalOperationErrorType, 
 
39
    permissionErrorType,
 
40
    userErrorType,
 
41
 
 
42
    -- * Throwing and catching I\/O errors
 
43
 
 
44
    ioError,                    -- :: IOError -> IO a
 
45
 
 
46
    catch,                      -- :: IO a -> (IOError -> IO a) -> IO a
 
47
    try                         -- :: IO a -> IO (Either IOError a)
 
48
 
 
49
  ) where
 
50
 
 
51
import "base" System.IO.Error hiding (IOError,catch,try)
 
52
import qualified "base" System.IO.Error as Base
 
53
import Prelude hiding (IOError,catch)
 
54
 
 
55
-- | Errors of type 'IOError' are used by the 'IO' monad.  This is an
 
56
-- abstract type; the module "System.IO.Error" provides functions to
 
57
-- interrogate and construct values of type 'IOError'.
 
58
type IOError = Base.IOError
 
59
 
 
60
-- SDM: duplicated docs for catch and try, omitting the part about non-IO
 
61
-- exceptions.
 
62
 
 
63
-- | The 'catch' function establishes a handler that receives any 'IOError'
 
64
-- raised in the action protected by 'catch'.  An 'IOError' is caught by
 
65
-- the most recent handler established by 'catch'.  These handlers are
 
66
-- not selective: all 'IOError's are caught.  Exception propagation
 
67
-- must be explicitly provided in a handler by re-raising any unwanted
 
68
-- exceptions.  For example, in
 
69
--
 
70
-- > f = catch g (\e -> if IO.isEOFError e then return [] else ioError e)
 
71
--
 
72
-- the function @f@ returns @[]@ when an end-of-file exception
 
73
-- (cf. 'System.IO.Error.isEOFError') occurs in @g@; otherwise, the
 
74
-- exception is propagated to the next outer handler.
 
75
--
 
76
-- When an exception propagates outside the main program, the Haskell
 
77
-- system prints the associated 'IOError' value and exits the program.
 
78
--
 
79
catch :: IO a -> (IOError -> IO a) -> IO a
 
80
catch = Base.catch
 
81
 
 
82
-- | The construct 'try' @comp@ exposes IO errors which occur within a
 
83
-- computation, and which are not fully handled.
 
84
--
 
85
try            :: IO a -> IO (Either IOError a)
 
86
try = Base.try