Movatterモバイル変換
[0]ホーム
{-# LANGUAGE Trustworthy #-}{-# LANGUAGE NoImplicitPrelude #-}------------------------------------------------------------------------------- |-- Module : System.IO.Error-- Copyright : (c) The University of Glasgow 2001-- License : BSD-style (see the file libraries/base/LICENSE)---- Maintainer : libraries@haskell.org-- Stability : provisional-- Portability : portable---- Standard IO Errors.-------------------------------------------------------------------------------moduleSystem.IO.Error(-- * I\/O errorsIOError,userError,mkIOError,annotateIOError,-- ** Classifying I\/O errorsisAlreadyExistsError,isDoesNotExistError,isAlreadyInUseError,isFullError,isEOFError,isIllegalOperation,isPermissionError,isUserError,-- ** Attributes of I\/O errorsioeGetErrorType,ioeGetLocation,ioeGetErrorString,ioeGetHandle,ioeGetFileName,ioeSetErrorType,ioeSetErrorString,ioeSetLocation,ioeSetHandle,ioeSetFileName,-- * Types of I\/O errorIOErrorType,-- abstractalreadyExistsErrorType,doesNotExistErrorType,alreadyInUseErrorType,fullErrorType,eofErrorType,illegalOperationErrorType,permissionErrorType,userErrorType,-- ** 'IOErrorType' predicatesisAlreadyExistsErrorType,isDoesNotExistErrorType,isAlreadyInUseErrorType,isFullErrorType,isEOFErrorType,isIllegalOperationErrorType,isPermissionErrorType,isUserErrorType,-- * Throwing and catching I\/O errorsioError,catchIOError,tryIOError,modifyIOError,)whereimportControl.Exception.BaseimportData.EitherimportData.MaybeimportGHC.BaseimportGHC.IOimportGHC.IO.ExceptionimportGHC.IO.Handle.TypesimportText.Show-- | The construct 'tryIOError' @comp@ exposes IO errors which occur within a-- computation, and which are not fully handled.---- Non-I\/O exceptions are not caught by this variant; to catch all-- exceptions, use 'Control.Exception.try' from "Control.Exception".---- @since 4.4.0.0tryIOError::IOa->IO(EitherIOErrora)tryIOErrorf=catch(dor<-freturn(Rightr))(return.Left)-- ------------------------------------------------------------------------------- Constructing an IOError-- | Construct an 'IOError' 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.mkIOError::IOErrorType->String->MaybeHandle->MaybeFilePath->IOErrormkIOErrortlocationmaybe_hdlmaybe_filename=IOError{ioe_type=t,ioe_location=location,ioe_description="",ioe_errno=Nothing,ioe_handle=maybe_hdl,ioe_filename=maybe_filename}-- ------------------------------------------------------------------------------- IOErrorType-- | An error indicating that an 'IO' operation failed because-- one of its arguments already exists.isAlreadyExistsError::IOError->BoolisAlreadyExistsError=isAlreadyExistsErrorType.ioeGetErrorType-- | An error indicating that an 'IO' operation failed because-- one of its arguments does not exist.isDoesNotExistError::IOError->BoolisDoesNotExistError=isDoesNotExistErrorType.ioeGetErrorType-- | An error indicating that an 'IO' 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).isAlreadyInUseError::IOError->BoolisAlreadyInUseError=isAlreadyInUseErrorType.ioeGetErrorType-- | An error indicating that an 'IO' operation failed because-- the device is full.isFullError::IOError->BoolisFullError=isFullErrorType.ioeGetErrorType-- | An error indicating that an 'IO' operation failed because-- the end of file has been reached.isEOFError::IOError->BoolisEOFError=isEOFErrorType.ioeGetErrorType-- | An error indicating that an 'IO' operation failed because-- the operation was not possible.-- Any computation which returns an 'IO' result may fail with-- 'isIllegalOperation'. In some cases, an implementation will not be-- able to distinguish between the possible error causes. In this case-- it should fail with 'isIllegalOperation'.isIllegalOperation::IOError->BoolisIllegalOperation=isIllegalOperationErrorType.ioeGetErrorType-- | An error indicating that an 'IO' operation failed because-- the user does not have sufficient operating system privilege-- to perform that operation.isPermissionError::IOError->BoolisPermissionError=isPermissionErrorType.ioeGetErrorType-- | A programmer-defined error value constructed using 'userError'.isUserError::IOError->BoolisUserError=isUserErrorType.ioeGetErrorType-- ------------------------------------------------------------------------------- IOErrorTypes-- | I\/O error where the operation failed because one of its arguments-- already exists.alreadyExistsErrorType::IOErrorTypealreadyExistsErrorType=AlreadyExists-- | I\/O error where the operation failed because one of its arguments-- does not exist.doesNotExistErrorType::IOErrorTypedoesNotExistErrorType=NoSuchThing-- | I\/O error where the operation failed because one of its arguments-- is a single-use resource, which is already being used.alreadyInUseErrorType::IOErrorTypealreadyInUseErrorType=ResourceBusy-- | I\/O error where the operation failed because the device is full.fullErrorType::IOErrorTypefullErrorType=ResourceExhausted-- | I\/O error where the operation failed because the end of file has-- been reached.eofErrorType::IOErrorTypeeofErrorType=EOF-- | I\/O error where the operation is not possible.illegalOperationErrorType::IOErrorTypeillegalOperationErrorType=IllegalOperation-- | I\/O error where the operation failed because the user does not-- have sufficient operating system privilege to perform that operation.permissionErrorType::IOErrorTypepermissionErrorType=PermissionDenied-- | I\/O error that is programmer-defined.userErrorType::IOErrorTypeuserErrorType=UserError-- ------------------------------------------------------------------------------- IOErrorType predicates-- | I\/O error where the operation failed because one of its arguments-- already exists.isAlreadyExistsErrorType::IOErrorType->BoolisAlreadyExistsErrorTypeAlreadyExists=TrueisAlreadyExistsErrorType_=False-- | I\/O error where the operation failed because one of its arguments-- does not exist.isDoesNotExistErrorType::IOErrorType->BoolisDoesNotExistErrorTypeNoSuchThing=TrueisDoesNotExistErrorType_=False-- | I\/O error where the operation failed because one of its arguments-- is a single-use resource, which is already being used.isAlreadyInUseErrorType::IOErrorType->BoolisAlreadyInUseErrorTypeResourceBusy=TrueisAlreadyInUseErrorType_=False-- | I\/O error where the operation failed because the device is full.isFullErrorType::IOErrorType->BoolisFullErrorTypeResourceExhausted=TrueisFullErrorType_=False-- | I\/O error where the operation failed because the end of file has-- been reached.isEOFErrorType::IOErrorType->BoolisEOFErrorTypeEOF=TrueisEOFErrorType_=False-- | I\/O error where the operation is not possible.isIllegalOperationErrorType::IOErrorType->BoolisIllegalOperationErrorTypeIllegalOperation=TrueisIllegalOperationErrorType_=False-- | I\/O error where the operation failed because the user does not-- have sufficient operating system privilege to perform that operation.isPermissionErrorType::IOErrorType->BoolisPermissionErrorTypePermissionDenied=TrueisPermissionErrorType_=False-- | I\/O error that is programmer-defined.isUserErrorType::IOErrorType->BoolisUserErrorTypeUserError=TrueisUserErrorType_=False-- ------------------------------------------------------------------------------- MiscellaneousioeGetErrorType::IOError->IOErrorTypeioeGetErrorString::IOError->StringioeGetLocation::IOError->StringioeGetHandle::IOError->MaybeHandleioeGetFileName::IOError->MaybeFilePathioeGetErrorTypeioe=ioe_typeioeioeGetErrorStringioe|isUserErrorType(ioe_typeioe)=ioe_descriptionioe|otherwise=show(ioe_typeioe)ioeGetLocationioe=ioe_locationioeioeGetHandleioe=ioe_handleioeioeGetFileNameioe=ioe_filenameioeioeSetErrorType::IOError->IOErrorType->IOErrorioeSetErrorString::IOError->String->IOErrorioeSetLocation::IOError->String->IOErrorioeSetHandle::IOError->Handle->IOErrorioeSetFileName::IOError->FilePath->IOErrorioeSetErrorTypeioeerrtype=ioe{ioe_type=errtype}ioeSetErrorStringioestr=ioe{ioe_description=str}ioeSetLocationioestr=ioe{ioe_location=str}ioeSetHandleioehdl=ioe{ioe_handle=Justhdl}ioeSetFileNameioefilename=ioe{ioe_filename=Justfilename}-- | Catch any 'IOError' that occurs in the computation and throw a-- modified version.modifyIOError::(IOError->IOError)->IOa->IOamodifyIOErrorfio=catchio(\e->ioError(fe))-- ------------------------------------------------------------------------------- annotating an IOError-- | Adds a location description and maybe a file path and file handle-- to an 'IOError'. If any of the file handle or file path is not given-- the corresponding value in the 'IOError' remains unaltered.annotateIOError::IOError->String->MaybeHandle->MaybeFilePath->IOErrorannotateIOErrorioelochdlpath=ioe{ioe_handle=hdl`mplus`ioe_handleioe,ioe_location=loc,ioe_filename=path`mplus`ioe_filenameioe}-- | The 'catchIOError' function establishes a handler that receives any-- 'IOError' raised in the action protected by 'catchIOError'.-- An 'IOError' is caught by-- the most recent handler established by one of the exception handling-- functions. These handlers are-- not selective: all 'IOError's are caught. Exception propagation-- must be explicitly provided in a handler by re-raising any unwanted-- exceptions. For example, in---- > f = catchIOError g (\e -> if IO.isEOFError e then return [] else ioError e)---- the function @f@ returns @[]@ when an end-of-file exception-- (cf. 'System.IO.Error.isEOFError') occurs in @g@; otherwise, the-- exception is propagated to the next outer handler.---- When an exception propagates outside the main program, the Haskell-- system prints the associated 'IOError' value and exits the program.---- Non-I\/O exceptions are not caught by this variant; to catch all-- exceptions, use 'Control.Exception.catch' from "Control.Exception".---- @since 4.4.0.0catchIOError::IOa->(IOError->IOa)->IOacatchIOError=catch
[8]ページ先頭