mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-12 17:07:17 +01:00
120 lines
3.5 KiB
Java
120 lines
3.5 KiB
Java
package rx.exceptions;
|
|
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import okio.Buffer$$ExternalSyntheticBUOutline0;
|
|
import rx.Observer;
|
|
import rx.SingleSubscriber;
|
|
import rx.annotations.Experimental;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes12.dex */
|
|
public final class Exceptions {
|
|
private static final int MAX_DEPTH = 25;
|
|
|
|
private Exceptions() {
|
|
throw new IllegalStateException("No instances!");
|
|
}
|
|
|
|
public static void addCause(Throwable th, Throwable th2) {
|
|
HashSet hashSet = new HashSet();
|
|
int i = 0;
|
|
while (th.getCause() != null) {
|
|
int i2 = i + 1;
|
|
if (i >= 25) {
|
|
return;
|
|
}
|
|
th = th.getCause();
|
|
if (!hashSet.contains(th.getCause())) {
|
|
hashSet.add(th.getCause());
|
|
i = i2;
|
|
}
|
|
}
|
|
try {
|
|
th.initCause(th2);
|
|
} catch (Throwable unused) {
|
|
}
|
|
}
|
|
|
|
public static Throwable getFinalCause(Throwable th) {
|
|
int i = 0;
|
|
while (th.getCause() != null) {
|
|
int i2 = i + 1;
|
|
if (i >= 25) {
|
|
return new RuntimeException("Stack too deep to get final cause");
|
|
}
|
|
th = th.getCause();
|
|
i = i2;
|
|
}
|
|
return th;
|
|
}
|
|
|
|
public static RuntimeException propagate(Throwable th) {
|
|
if (th instanceof RuntimeException) {
|
|
throw ((RuntimeException) th);
|
|
}
|
|
if (th instanceof Error) {
|
|
throw ((Error) th);
|
|
}
|
|
throw new RuntimeException(th);
|
|
}
|
|
|
|
public static void throwIfAny(List<? extends Throwable> list) {
|
|
if (list == null || list.isEmpty()) {
|
|
return;
|
|
}
|
|
if (list.size() != 1) {
|
|
throw new CompositeException(list);
|
|
}
|
|
Throwable th = list.get(0);
|
|
if (th instanceof RuntimeException) {
|
|
throw ((RuntimeException) th);
|
|
}
|
|
if (th instanceof Error) {
|
|
throw ((Error) th);
|
|
}
|
|
Buffer$$ExternalSyntheticBUOutline0.m(th);
|
|
}
|
|
|
|
public static void throwIfFatal(Throwable th) {
|
|
if (th instanceof OnErrorNotImplementedException) {
|
|
throw ((OnErrorNotImplementedException) th);
|
|
}
|
|
if (th instanceof OnErrorFailedException) {
|
|
throw ((OnErrorFailedException) th);
|
|
}
|
|
if (th instanceof OnCompletedFailedException) {
|
|
throw ((OnCompletedFailedException) th);
|
|
}
|
|
if (th instanceof StackOverflowError) {
|
|
throw ((StackOverflowError) th);
|
|
}
|
|
if (th instanceof VirtualMachineError) {
|
|
throw ((VirtualMachineError) th);
|
|
}
|
|
if (th instanceof ThreadDeath) {
|
|
throw ((ThreadDeath) th);
|
|
}
|
|
if (th instanceof LinkageError) {
|
|
throw ((LinkageError) th);
|
|
}
|
|
}
|
|
|
|
@Experimental
|
|
public static void throwOrReport(Throwable th, Observer<?> observer, Object obj) {
|
|
throwIfFatal(th);
|
|
observer.onError(OnErrorThrowable.addValueAsLastCause(th, obj));
|
|
}
|
|
|
|
@Experimental
|
|
public static void throwOrReport(Throwable th, Observer<?> observer) {
|
|
throwIfFatal(th);
|
|
observer.onError(th);
|
|
}
|
|
|
|
@Experimental
|
|
public static void throwOrReport(Throwable th, SingleSubscriber<?> singleSubscriber) {
|
|
throwIfFatal(th);
|
|
singleSubscriber.onError(th);
|
|
}
|
|
}
|