|Copyright||(c) The University of Glasgow 1998-2002|
|Portability||non-portable (GHC extensions)|
Exceptions and exception-handling functions.
Throw an exception. Exceptions may be thrown from purely functional code, but may only be caught within the
Defined in GHC.Exception
CallStacks are a lightweight method of obtaining a partial call-stack at any point in the program.
A function can request its call-site with the
HasCallStack constraint. For example, we can define
putStrLnWithCallStack :: HasCallStack => String -> IO ()
as a variant of
putStrLn that will get its call-site and print it, along with the string given as argument. We can access the call-stack inside
putStrLnWithCallStack :: HasCallStack => String -> IO () putStrLnWithCallStack msg = do putStrLn msg putStrLn (prettyCallStack callStack)
Thus, if we call
putStrLnWithCallStack we will get a formatted call-stack alongside our string.
>>> putStrLnWithCallStack "hello" hello CallStack (from HasCallStack): putStrLnWithCallStack, called at <interactive>:2:1 in interactive:Ghci1
HasCallStack constraints in three steps:
CallStackin scope -- i.e. the enclosing function has a
HasCallStackconstraint -- GHC will append the new call-site to the existing
CallStackin scope -- e.g. in the GHCi session above -- and the enclosing definition does not have an explicit type signature, GHC will infer a
HasCallStackconstraint for the enclosing definition (subject to the monomorphism restriction).
CallStackin scope and the enclosing definition has an explicit type signature, GHC will solve the
HasCallStackconstraint for the singleton
CallStackcontaining just the current call-site.
CallStacks do not interact with the RTS and do not require compilation with
-prof. On the other hand, as they are built up explicitly via the
HasCallStack constraints, they will generally not contain as much information as the simulated call-stacks maintained by the RTS.
NOTE: The intrepid user may notice that
HasCallStack is just an alias for an implicit parameter
?callStack :: CallStack. This is an implementation detail and should not be considered part of the
CallStack API, we may decide to change the implementation in the future.
|type Item CallStack|
Convert a list of call-sites to a
Extract a list of call-sites from the
The list is ordered by most recent call.
Pretty print a
A single location in the source code.
Pretty print a
© The University of Glasgow and others
Licensed under a BSD-style license (see top of the page).