limitations/exceptions.md
Monty implements a fixed set of exception classes, listed below. Sandboxed
code cannot define new exception classes (no class statement; see
language.md) — raise must use one of these built-ins.
BaseException, Exception, SystemExit, KeyboardInterrupt,
ArithmeticError, OverflowError, ZeroDivisionError, LookupError,
IndexError, KeyError, RuntimeError, NotImplementedError,
RecursionError, AttributeError, FrozenInstanceError, NameError,
UnboundLocalError, ValueError, UnicodeDecodeError, ImportError,
ModuleNotFoundError, OSError, FileNotFoundError, FileExistsError,
IsADirectoryError, NotADirectoryError, PermissionError,
AssertionError, MemoryError, StopIteration, SyntaxError,
TimeoutError, TypeError.
Module-specific: json.JSONDecodeError (subclass of ValueError),
re.PatternError / re.error, io.UnsupportedOperation (catchable as
both OSError and ValueError, matching CPython's dual parentage).
Warning and all its subclasses (DeprecationWarning, etc.),
BufferError, EOFError, FloatingPointError, GeneratorExit,
ConnectionError and subclasses (ConnectionAbortedError,
ConnectionRefusedError, ConnectionResetError,
BrokenPipeError), BlockingIOError, ChildProcessError,
InterruptedError, ProcessLookupError, ReferenceError,
StopAsyncIteration, SystemError, TabError, IndentationError,
UnicodeError (parent), UnicodeEncodeError, UnicodeTranslateError,
EncodingWarning, EnvironmentError / IOError aliases,
ExceptionGroup / BaseExceptionGroup (see language.md).
All exception constructors accept zero or one string argument only.
Multi-argument forms used in CPython (e.g. OSError(errno, strerror, filename), UnicodeDecodeError(encoding, obj, start, end, reason)) are
not supported — passing more than one argument raises an internal error.
exc.args — a tuple with 0 or 1 elements. Always a tuple, even when
empty.str(exc) — returns the single message string, or "" if none.repr(exc) — ClassName('message') matching CPython.Not implemented: __cause__, __context__, __suppress_context__,
__traceback__, __notes__, add_note(). The raise X from Y syntax
parses, but the from Y cause is silently dropped — chained
tracebacks are not preserved across raise from.
Because user class definitions are rejected at parse time, there is no
way to create a new exception class inside the sandbox. Define custom
exception types on the host side if needed, or use the built-in subclass
that best fits.
Tracebacks are formatted to match CPython, including the
File "...", line N, in <function> lines and ~ caret markers (Monty
uses ~ where CPython uses ^; the test harness normalizes between
them). Frame names use <module> for top-level code.