You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api.md
+26-6Lines changed: 26 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -514,28 +514,46 @@ except ConnectionError as e:
514
514
515
515
### QueryError
516
516
517
-
Raised when a query execution fails.
517
+
Raised when a non-Cassandra exception occurs during query execution. Most Cassandra driver exceptions (like `InvalidRequest`, `Unauthorized`, `AlreadyExists`, etc.) are passed through directly without wrapping.
518
518
519
519
```python
520
+
# Cassandra exceptions pass through directly
521
+
from cassandra import InvalidRequest, Unauthorized
522
+
520
523
try:
521
524
result = await session.execute("SELECT * FROM invalid_table")
525
+
except InvalidRequest as e:
526
+
print(f"Invalid query: {e}") # Cassandra exception passed through
522
527
except QueryError as e:
523
-
print(f"Query failed: {e}")
528
+
print(f"Unexpected error: {e}")# Only non-Cassandra exceptions wrapped
524
529
if e.cause:
525
530
print(f"Caused by: {e.cause}")
526
531
```
527
532
533
+
### Cassandra Driver Exceptions
534
+
535
+
The following Cassandra driver exceptions are passed through directly without wrapping:
536
+
-`InvalidRequest`- Invalid query syntax or schema issues
- Protocol exceptions like `SyntaxException`, `ServerError`
544
+
528
545
### Other Exceptions
529
546
530
-
The library also defines TimeoutError, AuthenticationError, andConfigurationError internally, but these are typically wrapped in the main exception types above. You should generally catch ConnectionErrorand QueryError in your code.
547
+
The library defines `ConnectionError`for connection-related issues and`QueryError`for wrapping unexpected non-Cassandra exceptions. Most of the time, you should catch specific Cassandra exceptions for proper error handling.
531
548
532
549
## Complete Example
533
550
534
551
```python
535
552
import asyncio
536
553
import uuid
537
554
from async_cassandra import AsyncCluster, AsyncCassandraSession
538
-
from async_cassandra.exceptions import QueryError, ConnectionError
555
+
from async_cassandra.exceptions importConnectionError
556
+
from cassandra import InvalidRequest, AlreadyExists
0 commit comments