Class CompletionExceptionLogHelper
- java.lang.Object
-
- com.apple.foundationdb.record.logging.CompletionExceptionLogHelper
-
@API(MAINTAINED) public class CompletionExceptionLogHelper extends Object
Helper class for helping with logging ofCompletionException
s. TheCompletionException
has a stack trace that indicates the call to a wait point, such asFDBRecordContext.asyncToSync(com.apple.foundationdb.record.provider.common.StoreTimer.Wait, java.util.concurrent.CompletableFuture<T>)
, which may be the only indication of what the caller was actually doing. But the cause of this exception is the one to analyze and wrap in an appropriate subclass ofRecordCoreException
, so that is returned, after remembering the original exception as a suppressed exception.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CompletionExceptionLogHelper.IgnoredSuppressedExceptionCount
A special "exception" to record the number of suppressed exceptions that were not recorded due to themaxSuppressedCount
.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Throwable
asCause(CompletionException ex)
Return the cause of the given exception and also arrange for the original exception to be in the suppressed chain.static Throwable
asCause(ExecutionException ex)
Return the cause of the given exception and also arrange for the original exception to be in the suppressed chain.static void
forceSetMaxSuppressedCountForTesting(int count)
Change the maximum number of suppressed exceptions to add to any given exception, even if the maximum has already been set.static void
setAddSuppressed(boolean addSuppressed)
Change whetherThrowable.addSuppressed(java.lang.Throwable)
is used.static boolean
setMaxSuppressedCountIfNotSet(int count)
Change the maximum number of suppressed exceptions to add to any given exception, if this maximum has not already been set.
-
-
-
Method Detail
-
setAddSuppressed
public static void setAddSuppressed(boolean addSuppressed)
Change whetherThrowable.addSuppressed(java.lang.Throwable)
is used. When enabled, the exception graph will have a circularity. This can cause problems for some logging frameworks and so may need to be disabled if using one of them.- Parameters:
addSuppressed
-true
to useaddSuppressed
to give more information in logs
-
setMaxSuppressedCountIfNotSet
public static boolean setMaxSuppressedCountIfNotSet(int count)
Change the maximum number of suppressed exceptions to add to any given exception, if this maximum has not already been set. Return whether or not the maximum was changed. This method only changes behavior whenaddSuppressed
istrue
.- Parameters:
count
- the new maximum count- Returns:
true
if the count was changed andfalse
if it was not
-
forceSetMaxSuppressedCountForTesting
@API(INTERNAL) public static void forceSetMaxSuppressedCountForTesting(int count)
Change the maximum number of suppressed exceptions to add to any given exception, even if the maximum has already been set. This should be done with extreme care:asCauseThrowable(Throwable)
may misbehave if it handles exceptions before and after this method is called with the samecause
. It should ONLY be used for testing without restarting the JVM.- Parameters:
count
- the new maximum count
-
asCause
public static Throwable asCause(@Nonnull CompletionException ex)
Return the cause of the given exception and also arrange for the original exception to be in the suppressed chain.- Parameters:
ex
- an exception fromCompletableFuture.join()
or the like- Returns:
- a throwable suitable for use as the cause of a wrapped exception
-
asCause
public static Throwable asCause(@Nonnull ExecutionException ex)
Return the cause of the given exception and also arrange for the original exception to be in the suppressed chain. However, if the given exception's cause already has the maximum number of suppressed exceptions specified bysetMaxSuppressedCountIfNotSet(int)
, then the given exception is not added to the suppressed chain and the exception counting the number of ignored exceptions is incremented instead.- Parameters:
ex
- an exception fromCompletableFuture.get()
or the like- Returns:
- a throwable suitable for use as the cause of a wrapped exception
-
-