Error Handling¶
This document describes error handling and exception types in Nexus.
Exception Hierarchy¶
NexusError (base)
├── NexusFileNotFoundError
├── NexusPermissionError
├── BackendError
├── InvalidPathError
└── MetadataError
Exception Details¶
NexusFileNotFoundError¶
try:
content = nx.read("/nonexistent.txt")
except NexusFileNotFoundError as e:
print(f"File not found: {e.path}")
InvalidPathError¶
try:
nx.write("no-leading-slash.txt", b"content") # Invalid
except InvalidPathError as e:
print(f"Invalid path: {e.path}")
BackendError¶
try:
nx.write("/file.txt", b"content")
except BackendError as e:
print(f"Backend error: {e.message}")
Best Practices¶
import nexus
from nexus import NexusFileNotFoundError, InvalidPathError
nx = nexus.connect()
try:
# Check before reading
if nx.exists("/file.txt"):
content = nx.read("/file.txt")
# Handle specific errors
nx.write("/documents/report.pdf", b"content")
except NexusFileNotFoundError as e:
print(f"File not found: {e.path}")
except InvalidPathError as e:
print(f"Invalid path: {e.path}")
except Exception as e:
print(f"Unexpected error: {e}")
finally:
nx.close()
See Also¶
- File Operations - File operation errors
- Permissions - Permission errors
- Advanced Usage - Error handling patterns
Next Steps¶
- Review file operations error conditions
- Implement proper exception handling
- Use best practices for error recovery