Movatterモバイル変換
[0]ホーム
{-# LANGUAGE Trustworthy #-}{-# LANGUAGE DeriveGeneric, NoImplicitPrelude, MagicHash, ExistentialQuantification, ImplicitParams #-}{-# OPTIONS_GHC -funbox-strict-fields #-}{-# OPTIONS_HADDOCK hide #-}------------------------------------------------------------------------------- |-- Module : GHC.IO.Exception-- Copyright : (c) The University of Glasgow, 2009-- License : see libraries/base/LICENSE---- Maintainer : libraries@haskell.org-- Stability : internal-- Portability : non-portable---- IO-related Exception types and functions-------------------------------------------------------------------------------moduleGHC.IO.Exception(BlockedIndefinitelyOnMVar(..),blockedIndefinitelyOnMVar,BlockedIndefinitelyOnSTM(..),blockedIndefinitelyOnSTM,Deadlock(..),AllocationLimitExceeded(..),allocationLimitExceeded,AssertionFailed(..),CompactionFailed(..),cannotCompactFunction,cannotCompactPinned,cannotCompactMutable,SomeAsyncException(..),asyncExceptionToException,asyncExceptionFromException,AsyncException(..),stackOverflow,heapOverflow,ArrayException(..),ExitCode(..),FixIOException(..),ioException,ioError,IOError,IOException(..),IOErrorType(..),userError,assertError,unsupportedOperation,untangle,)whereimportGHC.BaseimportGHC.GenericsimportGHC.ListimportGHC.IOimportGHC.ShowimportGHC.ReadimportGHC.ExceptionimportGHC.IO.Handle.TypesimportGHC.OldList(intercalate)import{-# SOURCE#-}GHC.Stack.CCSimportForeign.C.TypesimportData.Typeable(cast)-- -------------------------------------------------------------------------- Exception datatypes and operations-- |The thread is blocked on an @MVar@, but there are no other references-- to the @MVar@ so it can't ever continue.dataBlockedIndefinitelyOnMVar=BlockedIndefinitelyOnMVar-- | @since 4.1.0.0instanceExceptionBlockedIndefinitelyOnMVar-- | @since 4.1.0.0instanceShowBlockedIndefinitelyOnMVarwhereshowsPrec_BlockedIndefinitelyOnMVar=showString"thread blocked indefinitely in an MVar operation"blockedIndefinitelyOnMVar::SomeException-- for the RTSblockedIndefinitelyOnMVar=toExceptionBlockedIndefinitelyOnMVar------- |The thread is waiting to retry an STM transaction, but there are no-- other references to any @TVar@s involved, so it can't ever continue.dataBlockedIndefinitelyOnSTM=BlockedIndefinitelyOnSTM-- | @since 4.1.0.0instanceExceptionBlockedIndefinitelyOnSTM-- | @since 4.1.0.0instanceShowBlockedIndefinitelyOnSTMwhereshowsPrec_BlockedIndefinitelyOnSTM=showString"thread blocked indefinitely in an STM transaction"blockedIndefinitelyOnSTM::SomeException-- for the RTSblockedIndefinitelyOnSTM=toExceptionBlockedIndefinitelyOnSTM------- |There are no runnable threads, so the program is deadlocked.-- The @Deadlock@ exception is raised in the main thread only.dataDeadlock=Deadlock-- | @since 4.1.0.0instanceExceptionDeadlock-- | @since 4.1.0.0instanceShowDeadlockwhereshowsPrec_Deadlock=showString"<<deadlock>>"------- |This thread has exceeded its allocation limit. See-- 'System.Mem.setAllocationCounter' and-- 'System.Mem.enableAllocationLimit'.---- @since 4.8.0.0dataAllocationLimitExceeded=AllocationLimitExceeded-- | @since 4.8.0.0instanceExceptionAllocationLimitExceededwheretoException=asyncExceptionToExceptionfromException=asyncExceptionFromException-- | @since 4.7.1.0instanceShowAllocationLimitExceededwhereshowsPrec_AllocationLimitExceeded=showString"allocation limit exceeded"allocationLimitExceeded::SomeException-- for the RTSallocationLimitExceeded=toExceptionAllocationLimitExceeded------- | Compaction found an object that cannot be compacted. Functions-- cannot be compacted, nor can mutable objects or pinned objects.-- See 'GHC.Compact.compact'.---- @since 4.10.0.0newtypeCompactionFailed=CompactionFailedString-- | @since 4.10.0.0instanceExceptionCompactionFailedwhere-- | @since 4.10.0.0instanceShowCompactionFailedwhereshowsPrec_(CompactionFailedwhy)=showString("compaction failed: "++why)cannotCompactFunction::SomeException-- for the RTScannotCompactFunction=toException(CompactionFailed"cannot compact functions")cannotCompactPinned::SomeException-- for the RTScannotCompactPinned=toException(CompactionFailed"cannot compact pinned objects")cannotCompactMutable::SomeException-- for the RTScannotCompactMutable=toException(CompactionFailed"cannot compact mutable objects")------- |'assert' was applied to 'False'.newtypeAssertionFailed=AssertionFailedString-- | @since 4.1.0.0instanceExceptionAssertionFailed-- | @since 4.1.0.0instanceShowAssertionFailedwhereshowsPrec_(AssertionFailederr)=showStringerr------- |Superclass for asynchronous exceptions.---- @since 4.7.0.0dataSomeAsyncException=foralle.Exceptione=>SomeAsyncExceptione-- | @since 4.7.0.0instanceShowSomeAsyncExceptionwhereshow(SomeAsyncExceptione)=showe-- | @since 4.7.0.0instanceExceptionSomeAsyncException-- |@since 4.7.0.0asyncExceptionToException::Exceptione=>e->SomeExceptionasyncExceptionToException=toException.SomeAsyncException-- |@since 4.7.0.0asyncExceptionFromException::Exceptione=>SomeException->MaybeeasyncExceptionFromExceptionx=doSomeAsyncExceptiona<-fromExceptionxcasta-- |Asynchronous exceptions.dataAsyncException=StackOverflow-- ^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.|HeapOverflow-- ^The program\'s heap is reaching its limit, and-- the program should take action to reduce the amount of-- live data it has. Notes:---- * It is undefined which thread receives this exception.-- GHC currently throws this to the same thread that-- receives 'UserInterrupt', but this may change in the-- future.---- * The GHC RTS currently can only recover from heap overflow-- if it detects that an explicit memory limit (set via RTS flags).-- has been exceeded. Currently, failure to allocate memory from-- the operating system results in immediate termination of the-- program.|ThreadKilled-- ^This exception is raised by another thread-- calling 'Control.Concurrent.killThread', or by the system-- if it needs to terminate the thread for some-- reason.|UserInterrupt-- ^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).deriving(Eq-- ^ @since 4.2.0.0,Ord-- ^ @since 4.2.0.0)-- | @since 4.7.0.0instanceExceptionAsyncExceptionwheretoException=asyncExceptionToExceptionfromException=asyncExceptionFromException-- | Exceptions generated by array operationsdataArrayException=IndexOutOfBoundsString-- ^An attempt was made to index an array outside-- its declared bounds.|UndefinedElementString-- ^An attempt was made to evaluate an element of an-- array that had not been initialized.deriving(Eq-- ^ @since 4.2.0.0,Ord-- ^ @since 4.2.0.0)-- | @since 4.1.0.0instanceExceptionArrayException-- for the RTSstackOverflow,heapOverflow::SomeExceptionstackOverflow=toExceptionStackOverflowheapOverflow=toExceptionHeapOverflow-- | @since 4.1.0.0instanceShowAsyncExceptionwhereshowsPrec_StackOverflow=showString"stack overflow"showsPrec_HeapOverflow=showString"heap overflow"showsPrec_ThreadKilled=showString"thread killed"showsPrec_UserInterrupt=showString"user interrupt"-- | @since 4.1.0.0instanceShowArrayExceptionwhereshowsPrec_(IndexOutOfBoundss)=showString"array index out of range".(ifnot(nulls)thenshowString": ".showStringselseid)showsPrec_(UndefinedElements)=showString"undefined array element".(ifnot(nulls)thenshowString": ".showStringselseid)-- | The exception thrown when an infinite cycle is detected in 'fixIO'.---- @since 4.11.0.0dataFixIOException=FixIOException-- | @since 4.11.0.0instanceExceptionFixIOException-- | @since 4.11.0.0instanceShowFixIOExceptionwhereshowsPrec_FixIOException=showString"cyclic evaluation in fixIO"-- ------------------------------------------------------------------------------- The ExitCode type-- We need it here because it is used in ExitException in the-- Exception datatype (above).-- | Defines the exit codes that a program can return.dataExitCode=ExitSuccess-- ^ indicates successful termination;|ExitFailureInt-- ^ indicates program failure with an exit code.-- The exact interpretation of the code is-- operating-system dependent. In particular, some values-- may be prohibited (e.g. 0 on a POSIX-compliant system).deriving(Eq,Ord,Read,Show,Generic)-- | @since 4.1.0.0instanceExceptionExitCodeioException::IOException->IOaioExceptionerr=throwIOerr-- | Raise an 'IOError' in the 'IO' monad.ioError::IOError->IOaioError=ioException-- ----------------------------------------------------------------------------- IOError type-- | The Haskell 2010 type for exceptions in the 'IO' monad.-- Any I\/O operation may raise an 'IOError' instead of returning a result.-- For a more general type of exception, including also those that arise-- in pure code, see 'Control.Exception.Exception'.---- In Haskell 2010, this is an opaque type.typeIOError=IOException-- |Exceptions that occur in the @IO@ monad.-- An @IOException@ records a more specific error type, a descriptive-- string and maybe the handle that was used when the error was-- flagged.dataIOException=IOError{ioe_handle::MaybeHandle,-- the handle used by the action flagging-- the error.ioe_type::IOErrorType,-- what it was.ioe_location::String,-- location.ioe_description::String,-- error type specific information.ioe_errno::MaybeCInt,-- errno leading to this error, if any.ioe_filename::MaybeFilePath-- filename the error is related to.}-- | @since 4.1.0.0instanceExceptionIOException-- | @since 4.1.0.0instanceEqIOExceptionwhere(IOErrorh1e1loc1str1en1fn1)==(IOErrorh2e2loc2str2en2fn2)=e1==e2&&str1==str2&&h1==h2&&loc1==loc2&&en1==en2&&fn1==fn2-- | An abstract type that contains a value for each variant of 'IOError'.dataIOErrorType-- Haskell 2010:=AlreadyExists|NoSuchThing|ResourceBusy|ResourceExhausted|EOF|IllegalOperation|PermissionDenied|UserError-- GHC only:|UnsatisfiedConstraints|SystemError|ProtocolError|OtherError|InvalidArgument|InappropriateType|HardwareFault|UnsupportedOperation|TimeExpired|ResourceVanished|Interrupted-- | @since 4.1.0.0instanceEqIOErrorTypewherex==y=isTrue#(getTagx==#getTagy)-- | @since 4.1.0.0instanceShowIOErrorTypewhereshowsPrec_e=showString$caseeofAlreadyExists->"already exists"NoSuchThing->"does not exist"ResourceBusy->"resource busy"ResourceExhausted->"resource exhausted"EOF->"end of file"IllegalOperation->"illegal operation"PermissionDenied->"permission denied"UserError->"user error"HardwareFault->"hardware fault"InappropriateType->"inappropriate type"Interrupted->"interrupted"InvalidArgument->"invalid argument"OtherError->"failed"ProtocolError->"protocol error"ResourceVanished->"resource vanished"SystemError->"system error"TimeExpired->"timeout"UnsatisfiedConstraints->"unsatisfied constraints"-- ultra-precise!UnsupportedOperation->"unsupported operation"-- | Construct an 'IOError' value with a string describing the error.-- The 'fail' method of the 'IO' instance of the 'Monad' class raises a-- 'userError', thus:---- > instance Monad IO where-- > ...-- > fail s = ioError (userError s)--userError::String->IOErroruserErrorstr=IOErrorNothingUserError""strNothingNothing-- ----------------------------------------------------------------------------- Showing IOErrors-- | @since 4.1.0.0instanceShowIOExceptionwhereshowsPrecp(IOErrorhdliotlocs_fn)=(casefnofNothing->casehdlofNothing->idJusth->showsPrecph.showString": "Justname->showStringname.showString": ").(caselocof""->id_->showStringloc.showString": ").showsPrecpiot.(casesof""->id_->showString" (".showStrings.showString")")-- Note the use of "lazy". This means that-- assert False (throw e)-- will throw the assertion failure rather than e. See trac #5561.assertError::(?callStack::CallStack)=>Bool->a->aassertErrorpredicatev|predicate=lazyv|otherwise=unsafeDupablePerformIO$doccsStack<-currentCallStackletimplicitParamCallStack=prettyCallStackLines?callStackccsCallStack=showCCSStackccsStackstack=intercalate"\n"$implicitParamCallStack++ccsCallStackthrowIO(AssertionFailed("Assertion failed\n"++stack))unsupportedOperation::IOErrorunsupportedOperation=(IOErrorNothingUnsupportedOperation"""Operation is not supported"NothingNothing){-(untangle coded message) expects "coded" to be of the form "location|details"It prints location message details-}untangle::Addr#->String->Stringuntanglecodedmessage=location++": "++message++details++"\n"wherecoded_str=unpackCStringUtf8#coded(location,details)=case(spannot_barcoded_str)of{(loc,rest)->caserestof('|':det)->(loc,' ':det)_->(loc,"")}not_barc=c/='|'
[8]ページ先頭