Skip to content

Exceptions

Every driver exception implements the Cassandra\Exception marker interface and extends a matching SPL exception.

php
namespace Cassandra;

interface Exception {}

The tree

Cassandra\Exception  (interface)

├── Cassandra\Exception\LogicException            extends \LogicException
├── Cassandra\Exception\DomainException           extends \DomainException
├── Cassandra\Exception\InvalidArgumentException  extends \InvalidArgumentException
├── Cassandra\Exception\RangeException            extends \RangeException
│   └── Cassandra\Exception\DivideByZeroException

└── Cassandra\Exception\RuntimeException          extends \RuntimeException
    ├── Cassandra\Exception\TimeoutException
    ├── Cassandra\Exception\AuthenticationException
    ├── Cassandra\Exception\ProtocolException

    ├── Cassandra\Exception\ExecutionException
    │   ├── Cassandra\Exception\ReadTimeoutException
    │   ├── Cassandra\Exception\WriteTimeoutException
    │   ├── Cassandra\Exception\UnavailableException
    │   └── Cassandra\Exception\TruncateException

    ├── Cassandra\Exception\ValidationException
    │   ├── Cassandra\Exception\InvalidQueryException
    │   ├── Cassandra\Exception\InvalidSyntaxException
    │   ├── Cassandra\Exception\UnauthorizedException
    │   ├── Cassandra\Exception\UnpreparedException
    │   └── Cassandra\Exception\ConfigurationException
    │       └── Cassandra\Exception\AlreadyExistsException

    └── Cassandra\Exception\ServerException
        ├── Cassandra\Exception\IsBootstrappingException
        └── Cassandra\Exception\OverloadedException

Reference

ExceptionThrown whenRetry
InvalidArgumentExceptionA bad argument reaches the driver: an unknown option, a negative page size, an unreadable certificate path, a malformed addressNo
DivideByZeroExceptionA numeric value class divides by zeroNo
LogicExceptionAn operation is not valid for the object stateNo
DomainExceptionA value is outside the valid domainNo
RangeExceptionA numeric conversion is out of rangeNo
RuntimeExceptionA driver error with no more specific classDepends
TimeoutExceptionThe client wait expired. The request may still be running on the serverMaybe
AuthenticationExceptionThe credentials were rejectedNo
ProtocolExceptionA protocol-level disagreement with the serverNo
ReadTimeoutExceptionNot enough replicas answered a read in timeYes
WriteTimeoutExceptionNot enough replicas acknowledged a write in time. The write may have appliedOnly if idempotent
UnavailableExceptionNot enough live replicas to meet the consistency levelAfter a delay
TruncateExceptionA TRUNCATE failedYes
InvalidQueryExceptionThe table or column does not exist, or the query is not validNo
InvalidSyntaxExceptionThe CQL does not parseNo
UnauthorizedExceptionThe role lacks permissionNo
UnpreparedExceptionThe coordinator does not know the prepared statement identifierThe driver handles it
ConfigurationExceptionA schema statement is not validNo
AlreadyExistsExceptionA CREATE for something that existsNo
IsBootstrappingExceptionThe node is still joining the clusterAfter a delay
OverloadedExceptionThe node rejected the request under loadAfter a delay

Codes

Server-side exceptions carry the C driver error code in getCode(), and the driver message in getMessage().

php
catch (Cassandra\Exception $e) {
    $logger->error('cassandra error', [
        'class'   => $e::class,
        'code'    => $e->getCode(),
        'message' => $e->getMessage(),
    ]);
}

Catching by branch

The three branches under RuntimeException group the exceptions by what you should do about them.

php
try {
    $session->execute($statement, $options);
} catch (Cassandra\Exception\ValidationException $e) {
    // Your bug. Fix the query or the grant. Do not retry.
    throw $e;
} catch (Cassandra\Exception\ExecutionException $e) {
    // The cluster could not complete it. Retry when the statement is idempotent.
    $this->scheduleRetry();
} catch (Cassandra\Exception\ServerException $e) {
    // A node is not in a state to serve. Back off.
    $this->backOff();
} catch (Cassandra\Exception $e) {
    throw $e;
}

See error handling for the full guidance.

Version 1.4. Released under the Apache License 2.0.