⬅ Back to Table of Contents ⬅ Back to Math
This page documents the error and exception model in Pythonic, including the full error hierarchy, common error types, and idiomatic error handling.
All Pythonic exceptions inherit from pythonic::PythonicError, allowing you to catch all library errors with a single catch block, while still supporting granular error handling.
| Exception Type | Description | Example Usage |
|---|---|---|
PythonicError |
Base class for all Pythonic errors | catch (const PythonicError& e) |
PythonicWarning |
Base for warnings (not errors) | |
PythonicTypeError |
Wrong type operation | catch (const PythonicTypeError& e) |
PythonicValueError |
Right type, wrong value | |
PythonicIndexError |
Sequence index out of bounds | |
PythonicKeyError |
Mapping key not found | |
PythonicOverflowError |
Numeric overflow | |
PythonicZeroDivisionError |
Division or modulo by zero | |
PythonicFileError |
File operation failed | |
PythonicAttributeError |
Attribute reference/assignment failed | |
PythonicGraphError |
Graph-specific operation failure | |
PythonicIterationError |
Iterator exhausted or used incorrectly | |
PythonicStopIteration |
Signals iterator exhaustion (like Python) | |
PythonicRuntimeError |
General runtime error | |
PythonicNotImplementedError |
Feature not yet implemented |
Raised when an operation receives a value of the wrong type.
- Example:
"hello" * "world",Int("not a number")
Raised when a value is inappropriate (right type, wrong content).
- Example:
range(0, 10, 0),sqrt(-1)
Raised when a sequence index is out of range.
- Example:
list[100]whenlen(list) == 5
Raised when a mapping key is not found.
- Example:
dict["nonexistent_key"]
PythonicOverflowError: Raised when numeric operation overflows and promotion is exhausted.PythonicZeroDivisionError: Raised on division or modulo by zero.
Raised when a file operation fails (not found, cannot open, not open).
Raised when an attribute reference or assignment fails.
- Example: Calling
.upper()on an int
Raised for graph-specific operation failures (invalid node, edge not found, cycle detected).
PythonicIterationError: Raised when an iterator is exhausted or used incorrectly.PythonicStopIteration: Signals iterator exhaustion (like Python'sStopIteration).
PythonicRuntimeError: General runtime errors.PythonicNotImplementedError: Feature not yet implemented.
You can catch specific errors or all Pythonic errors:
try {
// Some operation that may fail
var result = Int("not a number");
} catch (const pythonic::PythonicTypeError& e) {
print("Type error:", e.what());
} catch (const pythonic::PythonicError& e) {
print("Any pythonic error:", e.what());
}try {
var x = INT_MAX;
var y = 1;
print(add(x, y)); // May throw PythonicOverflowError
} catch (const pythonic::PythonicOverflowError& e) {
print("Overflow:", e.what());
}try {
var lst = list(1,2,3);
print(lst[10]); // Throws PythonicIndexError
} catch (const pythonic::PythonicIndexError& e) {
print("Index error:", e.what());
}- All error messages are prefixed with
pythonic:for clarity. - Most errors support optional source location tracking for debugging (in debug builds).
- Use the
PYTHONIC_THROWmacro to throw with source location info. - Warnings (
PythonicWarning) can be caught separately from errors. - The error hierarchy allows both broad and fine-grained exception handling.