1 /* 2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"). 5 * You may not use this file except in compliance with the License. 6 * A copy of the License is located at 7 * 8 * http://aws.amazon.com/apache2.0 9 * 10 * or in the "license" file accompanying this file. This file is distributed 11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 * express or implied. See the License for the specific language governing 13 * permissions and limitations under the License. 14 */ 15 16 package software.amazon.awssdk.core.exception; 17 18 import software.amazon.awssdk.annotations.SdkPublicApi; 19 import software.amazon.awssdk.core.internal.retry.SdkDefaultRetrySetting; 20 21 /** 22 * Base type for all client exceptions thrown by the SDK. 23 * 24 * This exception is thrown when service could not be contacted for a response, 25 * or when client is unable to parse the response from service. 26 * <p> 27 * Exceptions that extend {@link SdkClientException} are assumed to be not retryable, with a few exceptions: 28 * <ul> 29 * <li>{@link RetryableException} - usable when calls should explicitly be retried</li> 30 * <li>Exceptions mentioned as a retryable exception in {@link SdkDefaultRetrySetting}</li> 31 * </ul> 32 * 33 * @see SdkServiceException 34 */ 35 @SdkPublicApi 36 public class SdkClientException extends SdkException { 37 SdkClientException(Builder b)38 protected SdkClientException(Builder b) { 39 super(b); 40 } 41 create(String message)42 public static SdkClientException create(String message) { 43 return SdkClientException.builder().message(message).build(); 44 } 45 create(String message, Throwable cause)46 public static SdkClientException create(String message, Throwable cause) { 47 return SdkClientException.builder().message(message).cause(cause).build(); 48 } 49 50 /** 51 * Create a {@link Builder} initialized with the properties of this {@code SdkClientException}. 52 * 53 * @return A new builder initialized with this config's properties. 54 */ 55 @Override toBuilder()56 public Builder toBuilder() { 57 return new BuilderImpl(this); 58 } 59 60 /** 61 * @return {@link Builder} instance to construct a new {@link SdkClientException}. 62 */ builder()63 public static Builder builder() { 64 return new BuilderImpl(); 65 } 66 67 public interface Builder extends SdkException.Builder { 68 69 @Override message(String message)70 Builder message(String message); 71 72 @Override cause(Throwable cause)73 Builder cause(Throwable cause); 74 75 @Override writableStackTrace(Boolean writableStackTrace)76 Builder writableStackTrace(Boolean writableStackTrace); 77 78 @Override build()79 SdkClientException build(); 80 } 81 82 protected static class BuilderImpl extends SdkException.BuilderImpl implements Builder { 83 BuilderImpl()84 protected BuilderImpl() { 85 } 86 BuilderImpl(SdkClientException ex)87 protected BuilderImpl(SdkClientException ex) { 88 super(ex); 89 } 90 91 @Override message(String message)92 public Builder message(String message) { 93 this.message = message; 94 return this; 95 } 96 97 @Override cause(Throwable cause)98 public Builder cause(Throwable cause) { 99 this.cause = cause; 100 return this; 101 } 102 103 @Override writableStackTrace(Boolean writableStackTrace)104 public Builder writableStackTrace(Boolean writableStackTrace) { 105 this.writableStackTrace = writableStackTrace; 106 return this; 107 } 108 109 @Override build()110 public SdkClientException build() { 111 return new SdkClientException(this); 112 } 113 } 114 } 115