Movatterモバイル変換
[0]ホーム
{-# LANGUAGE Trustworthy #-}{-# LANGUAGE NoImplicitPrelude , ExistentialQuantification , MagicHash , RecordWildCards , PatternSynonyms #-}{-# LANGUAGE DataKinds, PolyKinds #-}{-# OPTIONS_HADDOCK not-home #-}------------------------------------------------------------------------------- |-- Module : GHC.Exception-- Copyright : (c) The University of Glasgow, 1998-2002-- License : see libraries/base/LICENSE---- Maintainer : cvs-ghc@haskell.org-- Stability : internal-- Portability : non-portable (GHC extensions)---- Exceptions and exception-handling functions.-------------------------------------------------------------------------------moduleGHC.Exception(moduleGHC.Exception.Type,throw,ErrorCall(..,ErrorCall),errorCallException,errorCallWithCallStackException-- re-export CallStack and SrcLoc from GHC.Types,CallStack,fromCallSiteList,getCallStack,prettyCallStack,prettyCallStackLines,showCCSStack,SrcLoc(..),prettySrcLoc)whereimportGHC.BaseimportGHC.ShowimportGHC.Stack.TypesimportGHC.OldListimportGHC.IO.Unsafeimport{-# SOURCE#-}GHC.Stack.CCSimportGHC.Exception.Type-- | Throw an exception. Exceptions may be thrown from purely-- functional code, but may only be caught within the 'IO' monad.---- WARNING: You may want to use 'throwIO' instead so that your pure code-- stays exception-free.throw::forall(r::RuntimeRep).forall(a::TYPEr).foralle.Exceptione=>e->athrow :: forall a e. Exception e => e -> athrowee=SomeException -> aforall a b. a -> braise#(e -> SomeExceptionforall e. Exception e => e -> SomeExceptiontoExceptionee)-- | This is thrown when the user calls 'error'. The first @String@ is the-- argument given to 'error', second @String@ is the location.dataErrorCall=ErrorCallWithLocationStringStringderiving(ErrorCall -> ErrorCall -> Bool(ErrorCall -> ErrorCall -> Bool)-> (ErrorCall -> ErrorCall -> Bool) -> Eq ErrorCallforall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a$c== :: ErrorCall -> ErrorCall -> Bool== :: ErrorCall -> ErrorCall -> Bool$c/= :: ErrorCall -> ErrorCall -> Bool/= :: ErrorCall -> ErrorCall -> BoolEq-- ^ @since 4.7.0.0,Eq ErrorCallEq ErrorCall =>(ErrorCall -> ErrorCall -> Ordering)-> (ErrorCall -> ErrorCall -> Bool)-> (ErrorCall -> ErrorCall -> Bool)-> (ErrorCall -> ErrorCall -> Bool)-> (ErrorCall -> ErrorCall -> Bool)-> (ErrorCall -> ErrorCall -> ErrorCall)-> (ErrorCall -> ErrorCall -> ErrorCall)-> Ord ErrorCallErrorCall -> ErrorCall -> BoolErrorCall -> ErrorCall -> OrderingErrorCall -> ErrorCall -> ErrorCallforall a.Eq a =>(a -> a -> Ordering)-> (a -> a -> Bool)-> (a -> a -> Bool)-> (a -> a -> Bool)-> (a -> a -> Bool)-> (a -> a -> a)-> (a -> a -> a)-> Ord a$ccompare :: ErrorCall -> ErrorCall -> Orderingcompare :: ErrorCall -> ErrorCall -> Ordering$c< :: ErrorCall -> ErrorCall -> Bool< :: ErrorCall -> ErrorCall -> Bool$c<= :: ErrorCall -> ErrorCall -> Bool<= :: ErrorCall -> ErrorCall -> Bool$c> :: ErrorCall -> ErrorCall -> Bool> :: ErrorCall -> ErrorCall -> Bool$c>= :: ErrorCall -> ErrorCall -> Bool>= :: ErrorCall -> ErrorCall -> Bool$cmax :: ErrorCall -> ErrorCall -> ErrorCallmax :: ErrorCall -> ErrorCall -> ErrorCall$cmin :: ErrorCall -> ErrorCall -> ErrorCallmin :: ErrorCall -> ErrorCall -> ErrorCallOrd-- ^ @since 4.7.0.0)patternErrorCall::String->ErrorCallpattern$mErrorCall :: forall {r}. ErrorCall -> (String -> r) -> ((# #) -> r) -> r$bErrorCall :: String -> ErrorCallErrorCallerr<-ErrorCallWithLocationerr_whereErrorCallStringerr=String -> String -> ErrorCallErrorCallWithLocationStringerrString""{-# COMPLETEErrorCall#-}-- | @since 4.0.0.0instanceExceptionErrorCall-- | @since 4.0.0.0instanceShowErrorCallwhereshowsPrec :: Int -> ErrorCall -> ShowSshowsPrecInt_(ErrorCallWithLocationStringerrString"")=String -> ShowSshowStringStringerrshowsPrecInt_(ErrorCallWithLocationStringerrStringloc)=String -> ShowSshowStringStringerrShowS -> ShowS -> ShowSforall b c a. (b -> c) -> (a -> b) -> a -> c.Char -> ShowSshowCharChar'\n'ShowS -> ShowS -> ShowSforall b c a. (b -> c) -> (a -> b) -> a -> c.String -> ShowSshowStringStringlocerrorCallException::String->SomeExceptionerrorCallException :: String -> SomeExceptionerrorCallExceptionStrings=ErrorCall -> SomeExceptionforall e. Exception e => e -> SomeExceptiontoException(String -> ErrorCallErrorCallStrings)errorCallWithCallStackException::String->CallStack->SomeExceptionerrorCallWithCallStackException :: String -> CallStack -> SomeExceptionerrorCallWithCallStackExceptionStringsCallStackstk=IO SomeException -> SomeExceptionforall a. IO a -> aunsafeDupablePerformIO(IO SomeException -> SomeException)-> IO SomeException -> SomeExceptionforall a b. (a -> b) -> a -> b$do[String]ccsStack<-IO [String]currentCallStackletimplicitParamCallStack :: [String]implicitParamCallStack=CallStack -> [String]prettyCallStackLinesCallStackstkccsCallStack :: [String]ccsCallStack=[String] -> [String]showCCSStack[String]ccsStackstack :: Stringstack=String -> [String] -> Stringforall a. [a] -> [[a]] -> [a]intercalateString"\n"([String] -> String) -> [String] -> Stringforall a b. (a -> b) -> a -> b$[String]implicitParamCallStack[String] -> [String] -> [String]forall a. [a] -> [a] -> [a]++[String]ccsCallStackSomeException -> IO SomeExceptionforall a. a -> IO aforall (m :: * -> *) a. Monad m => a -> m areturn(SomeException -> IO SomeException)-> SomeException -> IO SomeExceptionforall a b. (a -> b) -> a -> b$ErrorCall -> SomeExceptionforall e. Exception e => e -> SomeExceptiontoException(String -> String -> ErrorCallErrorCallWithLocationStringsStringstack)showCCSStack::[String]->[String]showCCSStack :: [String] -> [String]showCCSStack[]=[]showCCSStack[String]stk=String"CallStack (from -prof):"String -> [String] -> [String]forall a. a -> [a] -> [a]:ShowS -> [String] -> [String]forall a b. (a -> b) -> [a] -> [b]map(String" "String -> ShowSforall a. [a] -> [a] -> [a]++)([String] -> [String]forall a. [a] -> [a]reverse[String]stk)-- prettySrcLoc and prettyCallStack are defined here to avoid hs-boot-- files. See Note [Definition of CallStack]-- | Pretty print a 'SrcLoc'.---- @since 4.9.0.0prettySrcLoc::SrcLoc->StringprettySrcLoc :: SrcLoc -> StringprettySrcLocSrcLoc{IntStringsrcLocPackage :: StringsrcLocModule :: StringsrcLocFile :: StringsrcLocStartLine :: IntsrcLocStartCol :: IntsrcLocEndLine :: IntsrcLocEndCol :: IntsrcLocEndCol :: SrcLoc -> IntsrcLocEndLine :: SrcLoc -> IntsrcLocStartCol :: SrcLoc -> IntsrcLocStartLine :: SrcLoc -> IntsrcLocFile :: SrcLoc -> StringsrcLocModule :: SrcLoc -> StringsrcLocPackage :: SrcLoc -> String..}=(String -> ShowS) -> String -> [String] -> Stringforall a b. (a -> b -> b) -> b -> [a] -> bfoldrString -> ShowSforall a. [a] -> [a] -> [a](++)String""[StringsrcLocFile,String":",Int -> Stringforall a. Show a => a -> StringshowIntsrcLocStartLine,String":",Int -> Stringforall a. Show a => a -> StringshowIntsrcLocStartCol,String" in ",StringsrcLocPackage,String":",StringsrcLocModule]-- | Pretty print a 'CallStack'.---- @since 4.9.0.0prettyCallStack::CallStack->StringprettyCallStack :: CallStack -> StringprettyCallStack=String -> [String] -> Stringforall a. [a] -> [[a]] -> [a]intercalateString"\n"([String] -> String)-> (CallStack -> [String]) -> CallStack -> Stringforall b c a. (b -> c) -> (a -> b) -> a -> c.CallStack -> [String]prettyCallStackLinesprettyCallStackLines::CallStack->[String]prettyCallStackLines :: CallStack -> [String]prettyCallStackLinesCallStackcs=caseCallStack -> [(String, SrcLoc)]getCallStackCallStackcsof[]->[][(String, SrcLoc)]stk->String"CallStack (from HasCallStack):"String -> [String] -> [String]forall a. a -> [a] -> [a]:((String, SrcLoc) -> String) -> [(String, SrcLoc)] -> [String]forall a b. (a -> b) -> [a] -> [b]map((String" "String -> ShowSforall a. [a] -> [a] -> [a]++)ShowS -> ((String, SrcLoc) -> String) -> (String, SrcLoc) -> Stringforall b c a. (b -> c) -> (a -> b) -> a -> c.(String, SrcLoc) -> StringprettyCallSite)[(String, SrcLoc)]stkwhereprettyCallSite :: (String, SrcLoc) -> StringprettyCallSite(Stringf,SrcLocloc)=StringfString -> ShowSforall a. [a] -> [a] -> [a]++String", called at "String -> ShowSforall a. [a] -> [a] -> [a]++SrcLoc -> StringprettySrcLocSrcLocloc
[8]ページ先頭