Errors API¶
Exception Hierarchy¶
TeehistorianError¶
Base exception for all teehistorian parsing errors.
All other exceptions inherit from this class.
Usage:
ParseError¶
Exception for parsing errors.
Inherits from TeehistorianError.
Raised when the parser encounters invalid data or cannot parse a chunk.
Usage:
try:
parser = th.Teehistorian(corrupted_data)
for chunk in parser:
pass
except th.ParseError as e:
print(f"Parse failed: {e}")
ValidationError¶
Exception for validation errors.
Inherits from TeehistorianError.
Raised when input data fails validation checks (e.g., empty data, too short, invalid format).
Usage:
FileError¶
Exception for file I/O errors.
Inherits from TeehistorianError.
Raised when there are issues reading or accessing the file.
Usage:
try:
with open("demo.teehistorian", "rb") as f:
data = f.read()
parser = th.Teehistorian(data)
except th.FileError as e:
print(f"File error: {e}")
Error Handling Best Practices¶
- Catch specific exceptions first: Handle more specific exceptions before the base exception
- Provide context: Include filename or other context in error messages
- Log errors appropriately: Use Python's logging module for production code
- Clean up resources: Use context managers for file handling
See Error Handling Guide for more detailed information and examples.