package h6; import android.util.Log; import com.google.android.gms.ads.RequestConfiguration; import java.io.IOException; import java.io.PrintStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; /* loaded from: classes2.dex */ public final class e extends Exception { /* renamed from: g, reason: collision with root package name */ private static final StackTraceElement[] f10368g = new StackTraceElement[0]; /* renamed from: a, reason: collision with root package name */ private final List f10369a; /* renamed from: b, reason: collision with root package name */ private e6.h f10370b; /* renamed from: c, reason: collision with root package name */ private e6.a f10371c; /* renamed from: d, reason: collision with root package name */ private Class f10372d; /* renamed from: e, reason: collision with root package name */ private String f10373e; /* renamed from: f, reason: collision with root package name */ private Exception f10374f; private static final class a implements Appendable { /* renamed from: a, reason: collision with root package name */ private final Appendable f10375a; /* renamed from: b, reason: collision with root package name */ private boolean f10376b = true; a(Appendable appendable) { this.f10375a = appendable; } private CharSequence a(CharSequence charSequence) { return charSequence == null ? RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED : charSequence; } @Override // java.lang.Appendable public Appendable append(char c10) { if (this.f10376b) { this.f10376b = false; this.f10375a.append(" "); } this.f10376b = c10 == '\n'; this.f10375a.append(c10); return this; } @Override // java.lang.Appendable public Appendable append(CharSequence charSequence) { CharSequence a10 = a(charSequence); return append(a10, 0, a10.length()); } @Override // java.lang.Appendable public Appendable append(CharSequence charSequence, int i10, int i11) { CharSequence a10 = a(charSequence); boolean z10 = false; if (this.f10376b) { this.f10376b = false; this.f10375a.append(" "); } if (a10.length() > 0 && a10.charAt(i11 - 1) == '\n') { z10 = true; } this.f10376b = z10; this.f10375a.append(a10, i10, i11); return this; } } public e(String str) { this(str, Collections.emptyList()); } private void c(Appendable appendable) { d(this, appendable); f(h(), new a(appendable)); } private static void d(Throwable th, Appendable appendable) { try { appendable.append(th.getClass().toString()).append(": ").append(th.getMessage()).append('\n'); } catch (IOException unused) { throw new RuntimeException(th); } } private void e(Throwable th, List list) { if (!(th instanceof e)) { list.add(th); return; } Iterator it = ((e) th).h().iterator(); while (it.hasNext()) { e((Throwable) it.next(), list); } } private static void f(List list, Appendable appendable) { try { g(list, appendable); } catch (IOException e10) { throw new RuntimeException(e10); } } private static void g(List list, Appendable appendable) { int size = list.size(); int i10 = 0; while (i10 < size) { int i11 = i10 + 1; appendable.append("Cause (").append(String.valueOf(i11)).append(" of ").append(String.valueOf(size)).append("): "); Throwable th = (Throwable) list.get(i10); if (th instanceof e) { ((e) th).c(appendable); } else { d(th, appendable); } i10 = i11; } } void a(e6.h hVar, e6.a aVar) { b(hVar, aVar, null); } void b(e6.h hVar, e6.a aVar, Class cls) { this.f10370b = hVar; this.f10371c = aVar; this.f10372d = cls; } @Override // java.lang.Throwable public Throwable fillInStackTrace() { return this; } @Override // java.lang.Throwable public String getMessage() { String str; StringBuilder sb = new StringBuilder(71); sb.append(this.f10373e); Class cls = this.f10372d; String str2 = RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED; sb.append(cls != null ? ", " + this.f10372d : RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED); sb.append(this.f10371c != null ? ", " + this.f10371c : RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED); if (this.f10370b != null) { str2 = ", " + this.f10370b; } sb.append(str2); List i10 = i(); if (i10.isEmpty()) { return sb.toString(); } if (i10.size() == 1) { str = "\nThere was 1 root cause:"; } else { sb.append("\nThere were "); sb.append(i10.size()); str = " root causes:"; } sb.append(str); for (Throwable th : i10) { sb.append('\n'); sb.append(th.getClass().getName()); sb.append('('); sb.append(th.getMessage()); sb.append(')'); } sb.append("\n call ImageModuleException#logRootCauses(String) for more detail"); return sb.toString(); } public List h() { return this.f10369a; } public List i() { ArrayList arrayList = new ArrayList(); e(this, arrayList); return arrayList; } public void j(String str) { List i10 = i(); int size = i10.size(); int i11 = 0; while (i11 < size) { StringBuilder sb = new StringBuilder(); sb.append("Root cause ("); int i12 = i11 + 1; sb.append(i12); sb.append(" of "); sb.append(size); sb.append(")"); Log.i(str, sb.toString(), (Throwable) i10.get(i11)); i11 = i12; } } public void k(Exception exc) { this.f10374f = exc; } @Override // java.lang.Throwable public void printStackTrace() { printStackTrace(System.err); } public e(String str, Throwable th) { this(str, Collections.singletonList(th)); } @Override // java.lang.Throwable public void printStackTrace(PrintStream printStream) { c(printStream); } public e(String str, List list) { this.f10373e = str; setStackTrace(f10368g); this.f10369a = list; } @Override // java.lang.Throwable public void printStackTrace(PrintWriter printWriter) { c(printWriter); } }