# Documentation

Lean.Exception

inductive Lean.Exception :
• Error messages that are displayed to users. ref is used to provide position information.

error:
• Internal exceptions that are not meant to be seen by users. Examples: "pospone elaboration", "stuck at universe constraint", etc

internal: Lean.InternalExceptionIdoptParam Lean.KVMap { entries := [] }Lean.Exception

Exception type used in most Lean monads

Instances For

Convert exception into a structured message.

Equations
• One or more equations did not get rendered due to their size.
Equations

Return syntax object providing position information for the exception. Recall that internal exceptions do not have position information.

Equations
Equations

Similar to AddMessageContext, but for error messages. The default instance just uses AddMessageContext. In error messages, we may want to provide additional information (e.g., macro expansion stack), and refine the (ref : Syntax).

Instances
instance Lean.instAddErrorMessageContext (m : ) [inst : ] [inst : ] :
Equations
• = { add := fun ref msg => do let msg ← pure (ref, msg) }
class Lean.MonadError (m : ) extends , , :
Instances
def Lean.throwError {m : } {α : Type} [inst : ] [inst : ] (msg : Lean.MessageData) :
m α

Throw an error exception using the given message data. The result of getRef is used as position information. Recall that getRef returns the current "reference" syntax.

Equations
def Lean.throwUnknownConstant {m : } {α : Type} [inst : ] [inst : ] (constName : Lean.Name) :
m α

Thrown an unknown constant error message.

Equations
def Lean.throwErrorAt {m : } {α : Type} [inst : ] [inst : ] (ref : Lean.Syntax) (msg : Lean.MessageData) :
m α

Throw an error exception using the given message data and reference syntax.

Equations
def Lean.ofExcept {m : } {ε : Type u_1} {α : Type} [inst : ] [inst : ] [inst : ] (x : Except ε α) :
m α

Convert an Except into a m monadic action, where m is any monad that implements MonadError.

Equations
def Lean.throwKernelException {m : } {α : Type} [inst : ] [inst : ] [inst : ] (ex : Lean.KernelException) :
m α

Throw an error exception for the given kernel exception.

Equations
def Lean.ofExceptKernelException {m : } {α : Type} [inst : ] [inst : ] [inst : ] (x : ) :
m α

Lift from Except KernelException to m when m can throw kernel exceptions.

Equations
• = match x with | => pure a | =>
class Lean.MonadRecDepth (m : ) :
• withRecDepth : {α : Type} → Natm αm α
• getRecDepth : m Nat
• getMaxRecDepth : m Nat
Instances
instance Lean.instMonadRecDepthReaderT {m : } {ρ : Type} [inst : ] [inst : ] :
Equations
• One or more equations did not get rendered due to their size.
instance Lean.instMonadRecDepthStateRefT' {m : } {ω : Type} {σ : Type} [inst : ] [inst : ] :
Equations
instance Lean.instMonadRecDepthMonadCacheT {α : Type} {m : } {ω : Type} {β : Type} [inst : BEq α] [inst : ] [inst : ] [inst : STWorld ω m] [inst : ] :
Equations
def Lean.throwMaxRecDepthAt {m : } {α : Type} [inst : ] (ref : Lean.Syntax) :
m α

Throw a "maximum recursion depth has been reached" exception using the given reference syntax.

Equations

Return true if ex was generated by throwMaxRecDepthAt. This function is a bit hackish. The max rec depth exception should probably be an internal exception, but it is also produced by MacroM which implemented in the prelude, and internal exceptions have not been defined yet.

Equations
• = match ex with | => | x => false
@[inline]
def Lean.withIncRecDepth {m : } {α : Type} [inst : ] [inst : ] [inst : ] (x : m α) :
m α

Increment the current recursion depth and then execute x. Throw an exception if maximum recursion depth has been reached. We use this combinator to prevent stack overflows.

Equations
• One or more equations did not get rendered due to their size.

Macro for throwing error exceptions. The argument can be an interpolated string. It is a convenient way of building MessageData objects. The result of getRef is used as position information. Recall that getRef returns the current "reference" syntax.

Equations
• One or more equations did not get rendered due to their size.

Macro for throwing error exceptions. The argument can be an interpolated string. It is a convenient way of building MessageData objects. The first argument must be a Syntax that provides position information for the error message. throwErrorAt ref msg is equivalent to withRef ref <| throwError msg

Equations
• One or more equations did not get rendered due to their size.