Exceptions¶
cysox uses a custom exception hierarchy for error handling.
Exception Hierarchy¶
Exception Classes¶
SoxError¶
Base exception for all cysox errors. Catch this to handle all cysox-related errors:
SoxInitError¶
Raised when library initialization or cleanup fails.
Common causes:
- libsox not properly installed
- Calling
init()when already initialized - Resource exhaustion
SoxFormatError¶
Raised when format operations fail.
Common causes:
- File not found
- Unsupported format
- Corrupt audio file
- Permission denied
SoxEffectError¶
Raised when effect operations fail.
Common causes:
- Invalid effect name
- Invalid effect options
- Effect chain misconfiguration
SoxIOError¶
Raised when I/O operations fail.
Common causes:
- Seek failure on non-seekable stream
- Write failure (disk full, permissions)
- Read failure (corrupt data)
SoxMemoryError¶
Raised when memory allocation fails.
Common causes:
- Out of memory
- Allocation too large
Best Practices¶
Specific Exception Handling¶
Handle specific exceptions when you need different behavior:
from cysox import sox
sox.init()
try:
with sox.Format('input.wav') as f:
samples = f.read(1024)
except sox.SoxFormatError:
print("Could not open file")
except sox.SoxIOError:
print("Could not read from file")
except sox.SoxError:
print("Unknown cysox error")
finally:
sox.quit()
Callback Exception Handling¶
Exceptions in callbacks cannot propagate through C code. Use
get_last_callback_exception() to retrieve them: