Exception Hierarchy
MontyError
Base exception for all Monty interpreter errors. CatchingMontyError will catch syntax, runtime, and typing errors from Monty. This exception is raised internally by Monty and cannot be constructed directly.
Methods
exception()
The underlying Python exception
__str__()
The exception message string
Example
MontySyntaxError
Raised when Python code has syntax errors or cannot be parsed by Monty. Inheritsexception() and __str__() from MontyError.
Methods
display()
Literal['type-msg', 'msg']
default:"'msg'"
'type-msg': Returns'ExceptionType: message'format'msg': Returns just the message
Formatted error message
Example
MontyTypingError
Raised when type checking finds errors in the code. This exception is raised when static type analysis detects type errors before execution. Inheritsexception() and __str__() from MontyError. Cannot be constructed directly from Python.
Methods
display()
Literal['full', 'concise', 'azure', 'json', 'jsonlines', 'rdjson', 'pylint', 'gitlab', 'github']
default:"'full'"
Output format for the diagnostics:
'full': Complete diagnostic output with context'concise': Abbreviated diagnostic output'azure': Azure Pipelines format'json': JSON format'jsonlines': JSON Lines format'rdjson': Reviewdog JSON format'pylint': Pylint format'gitlab': GitLab CI format'github': GitHub Actions format
bool
default:"False"
Whether to include ANSI color codes in the output
Formatted type error diagnostics
Example
MontyRuntimeError
Raised when Monty code fails during execution. Inheritsexception() and __str__() from MontyError. Additionally provides traceback() and display() methods.
Methods
traceback()
List of stack frames showing the call stack at the time of the error
display()
Literal['traceback', 'type-msg', 'msg']
default:"'traceback'"
'traceback': Full traceback with exception'type-msg':'ExceptionType: message'format'msg': Just the message
Formatted error output
Example
Frame
A single frame in a Monty traceback. This class provides detailed information about a specific point in the call stack.Properties
str
The filename where the code is located
int
Line number (1-based)
int
Column number (1-based)
int
End line number (1-based)
int
End column number (1-based)
str | None
The name of the function, or
None for module-level codestr | None
The source code line for preview in the traceback
Methods
dict()
Dictionary containing all frame properties
Example
Error Handling Best Practices
Catch Specific Exceptions
Handle Resource Limit Errors
Extract Detailed Information
Related
- Monty class - Main class that raises these exceptions
- ResourceLimits - Configure limits to prevent resource exhaustion
