package F1;

import kotlinx.coroutines.CoroutineExceptionHandler;
import n1.AbstractC0645a;

/* JADX INFO: loaded from: classes.dex */
public abstract class G {
    public static final void a(q1.g gVar, Throwable th) {
        try {
            CoroutineExceptionHandler coroutineExceptionHandler = (CoroutineExceptionHandler) gVar.get(CoroutineExceptionHandler.f5137X);
            if (coroutineExceptionHandler == null) {
                F.a(gVar, th);
            } else {
                coroutineExceptionHandler.handleException(gVar, th);
            }
        } catch (Throwable th2) {
            F.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);
        AbstractC0645a.a(runtimeException, th);
        return runtimeException;
    }
}
