package kotlinx.coroutines;

/* JADX INFO: compiled from: CoroutineExceptionHandler.kt */
/* JADX INFO: loaded from: classes.dex */
public final class k0 {
    public static final void a(h.u.g gVar, Throwable th) {
        try {
            CoroutineExceptionHandler coroutineExceptionHandler = (CoroutineExceptionHandler) gVar.b(CoroutineExceptionHandler.f1064c);
            if (coroutineExceptionHandler == null) {
                j0.a(gVar, th);
            } else {
                coroutineExceptionHandler.z(gVar, th);
            }
        } catch (Throwable th2) {
            j0.a(gVar, b(th, th2));
        }
    }

    public static final Throwable b(Throwable th, Throwable th2) {
        if (th == th2) {
            return th;
        }
        RuntimeException runtimeException = new RuntimeException("Exception while trying to handle coroutine exception", th2);
        h.b.a(runtimeException, th);
        return runtimeException;
    }
}
