Skip to content

Commit a999dd1

Browse files
committed
Document semantics of RetryException regarding cause and suppressed exceptions
Closes gh-35337
1 parent 9d57dab commit a999dd1

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

spring-core/src/main/java/org/springframework/core/retry/RetryException.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
/**
2323
* Exception thrown when a {@link RetryPolicy} has been exhausted.
2424
*
25+
* <p>A {@code RetryException} will contain the last exception thrown by the
26+
* {@link Retryable} operation as the {@linkplain #getCause() cause} and any
27+
* exceptions from previous attempts as {@linkplain #getSuppressed() suppressed
28+
* exceptions}.
29+
*
2530
* @author Mahmoud Ben Hassine
2631
* @since 7.0
2732
* @see RetryOperations

spring-core/src/main/java/org/springframework/core/retry/RetryOperations.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,17 @@
3434
public interface RetryOperations {
3535

3636
/**
37-
* Execute the given {@link Retryable} (according to the {@link RetryPolicy}
38-
* configured at the implementation level) until it succeeds, or eventually
39-
* throw an exception if the {@code RetryPolicy} is exhausted.
37+
* Execute the given {@link Retryable} operation according to the {@link RetryPolicy}
38+
* configured at the implementation level.
39+
* <p>If the {@code Retryable} succeeds, its result will be returned. Otherwise, a
40+
* {@link RetryException} will be thrown to the caller. The {@code RetryException}
41+
* will contain the last exception thrown by the {@code Retryable} operation as the
42+
* {@linkplain RetryException#getCause() cause} and any exceptions from previous
43+
* attempts as {@linkplain RetryException#getSuppressed() suppressed exceptions}.
4044
* @param retryable the {@code Retryable} to execute and retry if needed
4145
* @param <R> the type of the result
4246
* @return the result of the {@code Retryable}, if any
43-
* @throws RetryException if the {@code RetryPolicy} is exhausted; exceptions
44-
* encountered during retry attempts should be made available as suppressed
45-
* exceptions
47+
* @throws RetryException if the {@code RetryPolicy} is exhausted
4648
*/
4749
<R> @Nullable R execute(Retryable<? extends @Nullable R> retryable) throws RetryException;
4850

spring-core/src/main/java/org/springframework/core/retry/RetryTemplate.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,17 @@ public void setRetryListener(RetryListener retryListener) {
104104

105105

106106
/**
107-
* Execute the supplied {@link Retryable} according to the configured retry
108-
* and backoff policies.
109-
* <p>If the {@code Retryable} succeeds, its result will be returned. Otherwise,
110-
* a {@link RetryException} will be thrown to the caller.
107+
* Execute the supplied {@link Retryable} operation according to the configured
108+
* {@link RetryPolicy}.
109+
* <p>If the {@code Retryable} succeeds, its result will be returned. Otherwise, a
110+
* {@link RetryException} will be thrown to the caller. The {@code RetryException}
111+
* will contain the last exception thrown by the {@code Retryable} operation as the
112+
* {@linkplain RetryException#getCause() cause} and any exceptions from previous
113+
* attempts as {@linkplain RetryException#getSuppressed() suppressed exceptions}.
111114
* @param retryable the {@code Retryable} to execute and retry if needed
112115
* @param <R> the type of the result
113116
* @return the result of the {@code Retryable}, if any
114-
* @throws RetryException if the {@code RetryPolicy} is exhausted; exceptions
115-
* encountered during retry attempts are available as suppressed exceptions
117+
* @throws RetryException if the {@code RetryPolicy} is exhausted
116118
*/
117119
@Override
118120
public <R> @Nullable R execute(Retryable<? extends @Nullable R> retryable) throws RetryException {

0 commit comments

Comments
 (0)