Skip to main content

Overview

Monty provides three specialized error classes for different types of failures:
  • MontySyntaxError - Syntax or parsing errors
  • MontyRuntimeError - Runtime exceptions during execution
  • MontyTypingError - Static type checking errors
All error classes inherit from 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()

Returns formatted exception string.
'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 from MontyError.

Properties

string
'MontySyntaxError'
The inner exception 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 from MontyError.

Properties

string
'MontyRuntimeError'

Methods

traceback()

Returns the Monty traceback as an array of stack frames.
Frame[]
Array of stack frames where the error occurred

display()

Returns formatted exception string.
'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 from MontyError.

Properties

string
'MontyTypingError'
The inner exception typeName is always 'TypeError'.

Methods

displayDiagnostics()

Renders rich type error diagnostics for tooling integration.
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

All Monty errors inherit from MontyError, which inherits from JavaScript’s built-in Error class.

See Also