# Handle batch exceptions

The HBase API provides two ways to send multiple operations as a batch:

- [`Table#batch(List, Object[])`](https://hbase.apache.org/2.5/apidocs/org/apache/hadoop/hbase/client/Table.html#batch-java.util.List-java.lang.Object:A-) combines multiple gets and mutations into a single batch.
- [`BufferedMutator#mutate(List<? extends Mutation> mutations)`](https://hbase.apache.org/2.5/apidocs/org/apache/hadoop/hbase/client/BufferedMutator.html#mutate-java.util.List-) combines multiple mutations into a batch or series of batches.

With the Cloud Bigtable HBase client for Java, both of these methods can throw
a [`RetriesExhaustedWithDetailsException`](https://hbase.apache.org/2.5/apidocs/org/apache/hadoop/hbase/client/RetriesExhaustedWithDetailsException.html). This exception is thrown
when one or more of the batch operations fail for any reason (for example,
because the connection failed). It contains a list of failed requests, along
with details about the exception that caused each request to fail.

By itself, a `RetriesExhaustedWithDetailsException` does not tell you why a
request failed. You must call
[`RetriesExhaustedWithDetailsException#getCauses()`](https://hbase.apache.org/2.5/apidocs/org/apache/hadoop/hbase/client/RetriesExhaustedWithDetailsException.html#getCauses--) to retrieve the
detailed exceptions for each failed request. You can then log information about
each of the detailed exceptions, which will help you diagnose the failure:

    try {
      mutator.mutate(mutationList);
    } catch (RetriesExhaustedWithDetailsException e) {
      for (Throwable cause : e.getCauses()) {
        cause.printStackTrace();
      }
      throw e;
    }

An exception can also be thrown when you call
[`flush`](https://hbase.apache.org/2.5/devapidocs/org/apache/hadoop/hbase/procedure/flush/package-summary.html)
or [`close`](https://hbase.apache.org/2.5/apidocs/org/apache/hadoop/hbase/client/Connection.html#close--).
The same error handling applies.