

The Amazon SDK for Java 1.x reached end-of-support on December 31, 2025. We recommend that you migrate to the [Amazon SDK for Java 2.x](https://docs.amazonaws.cn/sdk-for-java/latest/developer-guide/home.html) to continue receiving new features, availability improvements, and security updates.

# Exception Handling
<a name="java-dg-exceptions"></a>

Understanding how and when the Amazon SDK for Java throws exceptions is important to building high-quality applications using the SDK. The following sections describe the different cases of exceptions that are thrown by the SDK and how to handle them appropriately.

## Why Unchecked Exceptions?
<a name="why-unchecked-exceptions"></a>

The Amazon SDK for Java uses runtime (or unchecked) exceptions instead of checked exceptions for these reasons:
+ To allow developers fine-grained control over the errors they want to handle without forcing them to handle exceptional cases they aren’t concerned about (and making their code overly verbose)
+ To prevent scalability issues inherent with checked exceptions in large applications

In general, checked exceptions work well on small scales, but can become troublesome as applications grow and become more complex.

For more information about the use of checked and unchecked exceptions, see:
+  [Unchecked Exceptions—​The Controversy](http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html) 
+  [The Trouble with Checked Exceptions](http://www.artima.com/intv/handcuffs2.html) 
+  [Java’s checked exceptions were a mistake (and here’s what I would like to do about it)](http://radio-weblogs.com/0122027/stories/2003/04/01/JavasCheckedExceptionsWereAMistake.html) 

## AmazonServiceException (and Subclasses)
<a name="amazonserviceexception-and-subclasses"></a>

 [AmazonServiceException](https://docs.amazonaws.cn/sdk-for-java/v1/reference/com/amazonaws/AmazonServiceException.html) is the most common exception that you’ll experience when using the Amazon SDK for Java. This exception represents an error response from an Amazon Web Services service. For example, if you try to terminate an Amazon EC2 instance that doesn’t exist, EC2 will return an error response and all the details of that error response will be included in the `AmazonServiceException` that’s thrown. For some cases, a subclass of `AmazonServiceException` is thrown to allow developers fine-grained control over handling error cases through catch blocks.

When you encounter an `AmazonServiceException`, you know that your request was successfully sent to the Amazon Web Services service but couldn’t be successfully processed. This can be because of errors in the request’s parameters or because of issues on the service side.

 `AmazonServiceException` provides you with information such as:
+ Returned HTTP status code
+ Returned Amazon error code
+ Detailed error message from the service
+  Amazon request ID for the failed request

 `AmazonServiceException` also includes information about whether the failed request was the caller’s fault (a request with illegal values) or the Amazon Web Services service's fault (an internal service error).

## AmazonClientException
<a name="amazonclientexception"></a>

 [AmazonClientException](https://docs.amazonaws.cn/sdk-for-java/v1/reference/com/amazonaws/AmazonClientException.html) indicates that a problem occurred inside the Java client code, either while trying to send a request to Amazon or while trying to parse a response from Amazon. An `AmazonClientException` is generally more severe than an `AmazonServiceException`, and indicates a major problem that is preventing the client from making service calls to Amazon services. For example, the Amazon SDK for Java throws an `AmazonClientException` if no network connection is available when you try to call an operation on one of the clients.