/* * Decompiled with CFR 0.152. */ package com.google.common.base; import com.google.common.annotations.Beta; import com.google.common.base.Preconditions; import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; import javax.annotation.Nullable; public final class Throwables { private Throwables() { } public static void propagateIfInstanceOf(@Nullable Throwable throwable, Class declaredType) throws X { if (throwable != null && declaredType.isInstance(throwable)) { throw (Throwable)declaredType.cast(throwable); } } public static void propagateIfPossible(@Nullable Throwable throwable) { Throwables.propagateIfInstanceOf(throwable, Error.class); Throwables.propagateIfInstanceOf(throwable, RuntimeException.class); } public static void propagateIfPossible(@Nullable Throwable throwable, Class declaredType) throws X { Throwables.propagateIfInstanceOf(throwable, declaredType); Throwables.propagateIfPossible(throwable); } public static void propagateIfPossible(@Nullable Throwable throwable, Class declaredType1, Class declaredType2) throws X1, X2 { Preconditions.checkNotNull(declaredType2); Throwables.propagateIfInstanceOf(throwable, declaredType1); Throwables.propagateIfPossible(throwable, declaredType2); } public static RuntimeException propagate(Throwable throwable) { Throwables.propagateIfPossible(Preconditions.checkNotNull(throwable)); throw new RuntimeException(throwable); } public static Throwable getRootCause(Throwable throwable) { Throwable cause; while ((cause = throwable.getCause()) != null) { throwable = cause; } return throwable; } @Beta public static List getCausalChain(Throwable throwable) { Preconditions.checkNotNull(throwable); ArrayList causes = new ArrayList(4); while (throwable != null) { causes.add(throwable); throwable = throwable.getCause(); } return Collections.unmodifiableList(causes); } public static String getStackTraceAsString(Throwable throwable) { StringWriter stringWriter = new StringWriter(); throwable.printStackTrace(new PrintWriter(stringWriter)); return stringWriter.toString(); } }