Error handling
On error, the Aerospike Python client raises an AerospikeError
exception or one of its subclasses. The exception includes the following attributes:
code
— The error code that identifies the error. See as_status.h of the Aerospike C client for error code descriptions.msg
— The error message with details.file
— The file where the error occurred.line
— The line number in the file where the error occurred.
Exception Handling
To handle the exceptions, wrap the code in a try-except
block:
from __future__ import print_function
import aerospikefrom aerospike.exception import *
try: config = { 'hosts': [ ('127.0.0.1', 3000)], 'policies': { 'timeout': 1200}} client = aerospike.client(config).connect() client.close()except ClientError as e: print("Error: {0} [{1}]".format(e.msg, e.code))