All Products
Search
Document Center

Handle exceptions

Last Updated: Mar 24, 2022

Time Series Database (TSDB) SDK cannot be used to forcibly handle exceptions. All exceptions are thrown by using the RuntimeException class. You can catch and handle exceptions based on your business requirements.

Common exceptions

Exception class

Description

HttpClientException

An exception occurs on the client.

HttpClientConnectionRefusedException

The TSDB server prevents the connection from being established.

HttpClientInitException

An exception occurs when the client is being initialized.

HttpClientSocketTimeoutException

The request times out.

HttpServerErrorException

A 5xx error code is returned by the TSDB server.

HttpServerNotSupportException

A 4xx error code is returned by the TSDB server.

HttpUnknowStatusException

The response code returned by the TSDB server is unknown.

BufferQueueFullException

The buffer queue for asynchronous requests is full.

Handle exceptions

Handle exceptions that occur when synchronous operations are performed

try {
    tsdb.ttl(10000);
} catch(HttpServerNotSupportException e) {
    int status = e.getStatus();
    String message = e.getMessage();
    System.err.println(status + "," + message);
} catch(HttpServerErrorException e) {
    int status = e.getStatus();
    String message = e.getMessage();
    System.err.println(status + "," + message);
}

Handle exceptions that occur when asynchronous operations are performed

Override the failed() method to handle an exception.

QueryCallback cb = new QueryCallback() {

    @Override
    public void response(Query input, List<QueryResult> result) {
        System.out.println("Query parameters:" + input);
        System.out.println("Returned result:" + result);
    }

    // Override the failed() method to handle an exception.
    @Override
    public void failed(Query request, Exception ex) {
        super.failed(request, ex);
    }

};
BatchPutCallback cb = new BatchPutCallback() {

    @Override
    public void response(List<Point> input, Result output) {
        long afterNum = num.addAndGet(input.size());
        System.out.println("Successful" + input.size() + ", Processed" + afterNum);
    }

    @Override
    public void failed(List<Point> input, Exception ex) {
        ex.printStackTrace();
        long afterNum = num.addAndGet(input.size());
        System.out.println("Failed" + input.size() + ", Processed" + afterNum);
    }
};