package h.a;

import java.lang.Thread;
import java.util.Iterator;
import java.util.List;

/* JADX INFO: compiled from: CoroutineExceptionHandlerImpl.kt */
/* JADX INFO: loaded from: classes.dex */
@g.i
public final class s {
    public static final List<r> a = f.a.y.a.j1(f.a.y.a.r(defpackage.a.a()));

    public static final void a(g.e0.f fVar, Throwable th) {
        Throwable runtimeException;
        Iterator<r> it = a.iterator();
        while (it.hasNext()) {
            try {
                it.next().handleException(fVar, th);
            } catch (Throwable th2) {
                Thread threadCurrentThread = Thread.currentThread();
                Thread.UncaughtExceptionHandler uncaughtExceptionHandler = threadCurrentThread.getUncaughtExceptionHandler();
                if (th == th2) {
                    runtimeException = th;
                } else {
                    runtimeException = new RuntimeException("Exception while trying to handle coroutine exception", th2);
                    f.a.y.a.m(runtimeException, th);
                }
                uncaughtExceptionHandler.uncaughtException(threadCurrentThread, runtimeException);
            }
        }
        Thread threadCurrentThread2 = Thread.currentThread();
        try {
            f.a.y.a.m(th, new y(fVar));
        } catch (Throwable th3) {
            f.a.y.a.L(th3);
        }
        threadCurrentThread2.getUncaughtExceptionHandler().uncaughtException(threadCurrentThread2, th);
    }
}
