Overview
Monty provides three specialized error classes for different types of failures:MontySyntaxError- Syntax or parsing errorsMontyRuntimeError- Runtime exceptions during executionMontyTypingError- Static type checking errors
MontyError, so you can catch any Monty exception with a single catch clause.
MontyError (Base Class)
Base class for all Monty interpreter errors.Properties
string
The error message (includes exception type and message)
string
The error name:
'MontyError'ExceptionInfo
Information about the inner Python exception
Methods
display()
'type-msg' | 'msg'
'msg'- Just the message (default)'type-msg'- Format as'ExceptionType: message'
string
Formatted exception string
Example
MontySyntaxError
Raised when Python code has syntax errors or cannot be parsed. Inherits all properties and methods fromMontyError.
Properties
string
'MontySyntaxError'typeName is always 'SyntaxError'.
Example
Common Syntax Errors
MontyRuntimeError
Raised when Monty code fails during execution. Provides access to the traceback and formatted error output. Inherits all properties and methods fromMontyError.
Properties
string
'MontyRuntimeError'Methods
traceback()
Frame[]
Array of stack frames where the error occurred
display()
'traceback' | 'type-msg' | 'msg'
'traceback'- Full traceback with stack frames (default)'type-msg'- Format as'ExceptionType: message''msg'- Just the message
string
Formatted exception string
Example: Basic Error Handling
Example: Inspecting Stack Frames
Common Runtime Errors
MontyTypingError
Raised when static type checking finds errors in the code. Inherits all properties and methods fromMontyError.
Properties
string
'MontyTypingError'typeName is always 'TypeError'.
Methods
displayDiagnostics()
TypingDisplayFormat
Output format (default:
'full')Options:'full'- Full diagnostic output with context'concise'- Concise single-line output'json'- JSON format'jsonlines'- JSON Lines format'github'- GitHub Actions format'gitlab'- GitLab CI format'azure'- Azure DevOps format'pylint'- Pylint format'rdjson'- Reviewdog JSON format
boolean
Include ANSI color codes (default:
false)string
Formatted diagnostic output
Example: Type Checking
Example: Manual Type Checking
Example: Different Output Formats
Catching All Monty Errors
Error Type Hierarchy
MontyError, which inherits from JavaScript’s built-in Error class.
See Also
- Monty Class - Main interpreter class
- Resource Limits - Prevent resource exhaustion errors
