package com.he.lynx;

import X.LhC;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Build;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.TextureView;
import android.view.View;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.sysoptimizer.ReceiverRegisterCrashOptimizer;
import com.bytedance.sysoptimizer.ReceiverRegisterLancet;
import com.he.lynx.loader.MediaLoader;
import com.he.lynx.player.HeliumPlayerImpl;
import com.he.lynx.player.IHeliumPlayer;
import com.lynx.tasm.base.LLog;
import java.lang.ref.WeakReference;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.CountDownLatch;

public final class HeliumApp {
    public static ScriptErrorHandler fatalErrorHandler;
    public static LoadSoInHostCallback loadSoInHostCallback;
    public static ScriptErrorHandler uncaughtExceptionHandler;
    public ContextWrapper context;
    public final Delegate delegate = new Delegate();
    public final List<Drawable> drawables = new ArrayList(1);
    public WeakReference<LynxDelegate> lynxDelegate = null;
    public PlatformCameraFactory mPlatformCameraFactory;
    public MediaLoader mediaLoader = new MediaLoader() {
        static {
            Covode.recordClassIndex(45633);
        }

        public Uri loadMedia(String str) {
            return Uri.parse(str);
        }

        public void onRequest(MediaLoader.RequestParams requestParams, MediaLoader.Responder responder) {
            if (responder != null) {
                responder.onResponse(true);
            }
        }
    };
    public IHeliumPlayer.HeliumPlayerFactory playerFactory = new IHeliumPlayer.HeliumPlayerFactory() {
        static {
            Covode.recordClassIndex(45632);
        }

        public IHeliumPlayer create() {
            return new HeliumPlayerImpl();
        }
    };
    public long ptr;
    public Set<StateCallback> resumables = new CopyOnWriteArraySet();
    public BroadcastReceiver screenReceiver;

    public static class EffectResourceDownloadInfo {
        public String appId;
        public String hostUrl;

        static {
            Covode.recordClassIndex(45640);
        }
    }

    public interface LoadSoCallback {
        static {
            Covode.recordClassIndex(45641);
        }

        void complete(boolean z, String str);
    }

    public interface LoadSoInHostCallback {
        static {
            Covode.recordClassIndex(45642);
        }

        void loadSoInHost(String str, LoadSoCallback loadSoCallback);
    }

    public interface LynxDelegate {
        static {
            Covode.recordClassIndex(45643);
        }

        EffectResourceDownloadInfo effectResourceDownloadInfo();

        void runOnJsThread(Runnable runnable);
    }

    public interface PlatformCameraFactory {
        static {
            Covode.recordClassIndex(45644);
        }

        IPlatformCamera createPlatformCamera();
    }

    public interface ScriptErrorHandler {
        static {
            Covode.recordClassIndex(45645);
        }

        void handle(String str);
    }

    public interface StateCallback {

        public enum CallType {
            SystemCall,
            JSBridge
        }

        static {
            Covode.recordClassIndex(45646);
        }

        void pause(CallType callType);

        void resume(CallType callType);
    }

    static {
        Covode.recordClassIndex(45631);
    }

    public final PlatformCameraFactory getPlatformCameraFactory() {
        return this.mPlatformCameraFactory;
    }

    public final IHeliumPlayer createPlayer() {
        return this.playerFactory.create();
    }

    public final EffectResourceDownloadInfo effectResourceDownloadInfo() {
        LynxDelegate lynxDelegate2 = (LynxDelegate) this.lynxDelegate.get();
        if (lynxDelegate2 != null) {
            return lynxDelegate2.effectResourceDownloadInfo();
        }
        LLog.LIZ(6, "HeliumApp", "effectResourceDownloadUrl delegate error ");
        return null;
    }

    public static boolean loadEffectInHost() {
        final CountDownLatch countDownLatch = new CountDownLatch(1);
        final boolean[] zArr = {false};
        LoadSoInHostCallback loadSoInHostCallback2 = loadSoInHostCallback;
        if (loadSoInHostCallback2 != null) {
            loadSoInHostCallback2.loadSoInHost("libeffect.so", new LoadSoCallback() {
                static {
                    Covode.recordClassIndex(45634);
                }

                public final void complete(boolean z, String str) {
                    zArr[0] = z;
                    if (!z) {
                        LLog.LIZ(6, "HeliumApp", "loadEffectInHost failed with msg : ".concat(String.valueOf(str)));
                    }
                    countDownLatch.countDown();
                }
            });
            try {
                countDownLatch.await();
            } catch (InterruptedException e) {
                LLog.LIZ(6, "HeliumApp", e.getMessage());
            }
        }
        return zArr[0];
    }

    public final void cleanup() {
        MethodCollector.i(8730);
        this.delegate.destroyed = true;
        BroadcastReceiver broadcastReceiver = this.screenReceiver;
        if (broadcastReceiver != null) {
            this.context.unregisterReceiver(broadcastReceiver);
            this.screenReceiver = null;
        }
        this.context = null;
        for (Drawable next : this.drawables) {
            if (next.view != null) {
                next.view.setOnTouchListener((View.OnTouchListener) null);
            }
            next.holder.removeCallback(this.delegate);
        }
        this.drawables.clear();
        this.resumables.clear();
        synchronized (this.delegate) {
            try {
                long j = this.ptr;
                if (j != 0) {
                    Helium.cleanup(j);
                    this.ptr = 0;
                }
            } finally {
                MethodCollector.o(8730);
            }
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:13:0x0022, code lost:
        return;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:17:0x002e, code lost:
        r2 = r4.resumables.iterator();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:19:0x0038, code lost:
        if (r2.hasNext() == false) goto L_0x0046;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:20:0x003a, code lost:
        r2.next().pause(com.he.lynx.HeliumApp.StateCallback.CallType.SystemCall);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:21:0x0046, code lost:
        com.bytedance.frameworks.apm.trace.MethodCollector.o(8732);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:22:0x0049, code lost:
        return;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final void pause() {
        /*
            r4 = this;
            r3 = 8732(0x221c, float:1.2236E-41)
            com.bytedance.frameworks.apm.trace.MethodCollector.i(r3)
            com.he.lynx.HeliumApp$Delegate r0 = r4.delegate
            boolean r0 = r0.destroyed
            if (r0 == 0) goto L_0x000f
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r3)
            return
        L_0x000f:
            com.he.lynx.HeliumApp$Delegate r2 = r4.delegate
            monitor-enter(r2)
            com.he.lynx.HeliumApp$Delegate r0 = r4.delegate     // Catch:{ all -> 0x004a }
            boolean r0 = r0.destroyed     // Catch:{ all -> 0x004a }
            if (r0 != 0) goto L_0x001e
            com.he.lynx.HeliumApp$Delegate r0 = r4.delegate     // Catch:{ all -> 0x004a }
            boolean r0 = r0.paused     // Catch:{ all -> 0x004a }
            if (r0 == 0) goto L_0x0023
        L_0x001e:
            monitor-exit(r2)     // Catch:{ all -> 0x004a }
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r3)
            return
        L_0x0023:
            com.he.lynx.HeliumApp$Delegate r1 = r4.delegate     // Catch:{ all -> 0x004a }
            r0 = 1
            r1.paused = r0     // Catch:{ all -> 0x004a }
            long r0 = r4.ptr     // Catch:{ all -> 0x004a }
            com.he.lynx.Helium.onPause(r0)     // Catch:{ all -> 0x004a }
            monitor-exit(r2)     // Catch:{ all -> 0x004a }
            java.util.Set<com.he.lynx.HeliumApp$StateCallback> r0 = r4.resumables
            java.util.Iterator r2 = r0.iterator()
        L_0x0034:
            boolean r0 = r2.hasNext()
            if (r0 == 0) goto L_0x0046
            java.lang.Object r1 = r2.next()
            com.he.lynx.HeliumApp$StateCallback r1 = (com.he.lynx.HeliumApp.StateCallback) r1
            com.he.lynx.HeliumApp$StateCallback$CallType r0 = com.he.lynx.HeliumApp.StateCallback.CallType.SystemCall
            r1.pause(r0)
            goto L_0x0034
        L_0x0046:
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r3)
            return
        L_0x004a:
            r0 = move-exception
            monitor-exit(r2)
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r3)
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.he.lynx.HeliumApp.pause():void");
    }

    /* JADX WARNING: Code restructure failed: missing block: B:13:0x0022, code lost:
        return;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:17:0x002e, code lost:
        r2 = r4.resumables.iterator();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:19:0x0038, code lost:
        if (r2.hasNext() == false) goto L_0x0046;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:20:0x003a, code lost:
        r2.next().resume(com.he.lynx.HeliumApp.StateCallback.CallType.SystemCall);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:21:0x0046, code lost:
        com.bytedance.frameworks.apm.trace.MethodCollector.o(8923);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:22:0x0049, code lost:
        return;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final void resume() {
        /*
            r4 = this;
            r3 = 8923(0x22db, float:1.2504E-41)
            com.bytedance.frameworks.apm.trace.MethodCollector.i(r3)
            com.he.lynx.HeliumApp$Delegate r0 = r4.delegate
            boolean r0 = r0.destroyed
            if (r0 == 0) goto L_0x000f
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r3)
            return
        L_0x000f:
            com.he.lynx.HeliumApp$Delegate r2 = r4.delegate
            monitor-enter(r2)
            com.he.lynx.HeliumApp$Delegate r0 = r4.delegate     // Catch:{ all -> 0x004a }
            boolean r0 = r0.destroyed     // Catch:{ all -> 0x004a }
            if (r0 != 0) goto L_0x001e
            com.he.lynx.HeliumApp$Delegate r0 = r4.delegate     // Catch:{ all -> 0x004a }
            boolean r0 = r0.paused     // Catch:{ all -> 0x004a }
            if (r0 != 0) goto L_0x0023
        L_0x001e:
            monitor-exit(r2)     // Catch:{ all -> 0x004a }
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r3)
            return
        L_0x0023:
            com.he.lynx.HeliumApp$Delegate r1 = r4.delegate     // Catch:{ all -> 0x004a }
            r0 = 0
            r1.paused = r0     // Catch:{ all -> 0x004a }
            long r0 = r4.ptr     // Catch:{ all -> 0x004a }
            com.he.lynx.Helium.onResume(r0)     // Catch:{ all -> 0x004a }
            monitor-exit(r2)     // Catch:{ all -> 0x004a }
            java.util.Set<com.he.lynx.HeliumApp$StateCallback> r0 = r4.resumables
            java.util.Iterator r2 = r0.iterator()
        L_0x0034:
            boolean r0 = r2.hasNext()
            if (r0 == 0) goto L_0x0046
            java.lang.Object r1 = r2.next()
            com.he.lynx.HeliumApp$StateCallback r1 = (com.he.lynx.HeliumApp.StateCallback) r1
            com.he.lynx.HeliumApp$StateCallback$CallType r0 = com.he.lynx.HeliumApp.StateCallback.CallType.SystemCall
            r1.resume(r0)
            goto L_0x0034
        L_0x0046:
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r3)
            return
        L_0x004a:
            r0 = move-exception
            monitor-exit(r2)
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r3)
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.he.lynx.HeliumApp.resume():void");
    }

    public static void setFatalErrorHandler(ScriptErrorHandler scriptErrorHandler) {
        fatalErrorHandler = scriptErrorHandler;
    }

    public static void setLoadSoInHostCallback(LoadSoInHostCallback loadSoInHostCallback2) {
        loadSoInHostCallback = loadSoInHostCallback2;
    }

    public static void setUncaughtExceptionHandler(ScriptErrorHandler scriptErrorHandler) {
        uncaughtExceptionHandler = scriptErrorHandler;
    }

    public final void setHeliumPlayerFactory(IHeliumPlayer.HeliumPlayerFactory heliumPlayerFactory) {
        this.playerFactory = heliumPlayerFactory;
    }

    public final void setPlatformCameraFactory(PlatformCameraFactory platformCameraFactory) {
        this.mPlatformCameraFactory = platformCameraFactory;
    }

    public class Delegate implements SurfaceHolder.Callback, View.OnTouchListener {
        public boolean destroyed;
        public boolean paused;

        static {
            Covode.recordClassIndex(45639);
        }

        public Delegate() {
        }

        public void surfaceCreated(SurfaceHolder surfaceHolder) {
            MethodCollector.i(7058);
            long findSurface = findSurface(surfaceHolder);
            if (findSurface != 0) {
                Helium.onSurfaceCreated(HeliumApp.this.ptr, findSurface, surfaceHolder.getSurface());
            }
            MethodCollector.o(7058);
        }

        public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
            MethodCollector.i(7063);
            long findSurface = findSurface(surfaceHolder);
            if (findSurface != 0) {
                Helium.onSurfaceDestroyed(HeliumApp.this.ptr, findSurface);
            }
            MethodCollector.o(7063);
        }

        private long findSurface(SurfaceHolder surfaceHolder) {
            for (int i = 0; i < HeliumApp.this.drawables.size(); i++) {
                Drawable drawable = HeliumApp.this.drawables.get(i);
                if (drawable.holder == surfaceHolder) {
                    return drawable.ptr;
                }
            }
            return 0;
        }

        public final void doFrame(long j) {
            MethodCollector.i(7065);
            if (this.destroyed || this.paused) {
                MethodCollector.o(7065);
                return;
            }
            if (HeliumApp.this.ptr != 0) {
                Helium.doFrame(HeliumApp.this.ptr);
            }
            MethodCollector.o(7065);
        }

        public boolean onTouch(View view, MotionEvent motionEvent) {
            for (int i = 0; i < HeliumApp.this.drawables.size(); i++) {
                Drawable drawable = HeliumApp.this.drawables.get(i);
                if (drawable.view == view) {
                    HeliumApp.this.dispatch(drawable, motionEvent);
                }
            }
            return true;
        }

        public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) {
            MethodCollector.i(7060);
            long findSurface = findSurface(surfaceHolder);
            if (findSurface != 0) {
                Helium.onSurfaceChanged(HeliumApp.this.ptr, findSurface, i2, i3);
            }
            MethodCollector.o(7060);
        }
    }

    public final void doFrame(long j) {
        this.delegate.doFrame(j);
    }

    public final Drawable addView(SurfaceView surfaceView) {
        return addViewInternal(surfaceView, surfaceView.getHolder());
    }

    private Surface getSurface(SurfaceHolder surfaceHolder) {
        MethodCollector.i(8676);
        Surface surface = surfaceHolder.getSurface();
        for (int i = 0; i < 5; i++) {
            try {
                Thread.sleep(17);
            } catch (InterruptedException unused) {
            }
            surface = surfaceHolder.getSurface();
        }
        MethodCollector.o(8676);
        return surface;
    }

    public final void dispatchToJSThread(Runnable runnable) {
        LynxDelegate lynxDelegate2;
        if (runnable != null && (lynxDelegate2 = (LynxDelegate) this.lynxDelegate.get()) != null) {
            lynxDelegate2.runOnJsThread(runnable);
        }
    }

    public final void removeView(Drawable drawable) {
        MethodCollector.i(8727);
        this.drawables.remove(drawable);
        if (drawable.view instanceof TextureView) {
            Helium.onSurfaceDestroyed(this.ptr, drawable.ptr);
        }
        if (drawable.holder != null) {
            drawable.holder.removeCallback(this.delegate);
        }
        if (drawable.view != null) {
            drawable.view.setOnTouchListener((View.OnTouchListener) null);
        }
        MethodCollector.o(8727);
    }

    public final Drawable addSurfaceHolder(SurfaceHolder surfaceHolder) {
        MethodCollector.i(7735);
        if (surfaceHolder == null) {
            MethodCollector.o(7735);
            return null;
        }
        Surface surface = getSurface(surfaceHolder);
        if (surface != null) {
            long j = this.ptr;
            if (j != 0) {
                long addView = Helium.addView(j, surface);
                if (addView != 0) {
                    Drawable createDrawable = createDrawable(addView, (View) null, surfaceHolder);
                    MethodCollector.o(7735);
                    return createDrawable;
                }
                RuntimeException runtimeException = new RuntimeException("failed to create EGLSurface");
                MethodCollector.o(7735);
                throw runtimeException;
            }
            RuntimeException runtimeException2 = new RuntimeException("heliumAppPtr is null");
            MethodCollector.o(7735);
            throw runtimeException2;
        }
        RuntimeException runtimeException3 = new RuntimeException("surface is null");
        MethodCollector.o(7735);
        throw runtimeException3;
    }

    public HeliumApp(ContextWrapper contextWrapper, LynxDelegate lynxDelegate2) {
        this.context = contextWrapper;
        this.lynxDelegate = new WeakReference<>(lynxDelegate2);
    }

    public static boolean setHostSensitivePermissionStatus(String str, boolean z) {
        MethodCollector.i(8480);
        if (str != null) {
            if (str.equals("camera")) {
                Helium.setSensitivePermissionStatus(0, z);
                Helium.cameraPermission = z;
                MethodCollector.o(8480);
                return true;
            } else if (str.equals("record")) {
                Helium.setSensitivePermissionStatus(1, z);
                MethodCollector.o(8480);
                return true;
            }
        }
        MethodCollector.o(8480);
        return false;
    }

    public final Drawable addView(TextureView textureView, SurfaceHolder surfaceHolder) {
        if (Build.VERSION.SDK_INT >= 24 && this.screenReceiver == null) {
            this.screenReceiver = new BroadcastReceiver() {
                static {
                    Covode.recordClassIndex(45635);
                }

                public void onReceive(Context context, Intent intent) {
                    HeliumApp.this.dispatchToJSThread(new Runnable() {
                        static {
                            Covode.recordClassIndex(45636);
                        }

                        public void run() {
                            for (Drawable drawable : HeliumApp.this.drawables) {
                                final View view = drawable.view;
                                LhC.LIZ(new Runnable() {
                                    static {
                                        Covode.recordClassIndex(45637);
                                    }

                                    public void run() {
                                        View view = view;
                                        if (view != null && (view instanceof TextureView) && view.getVisibility() == 0) {
                                            view.setVisibility(4);
                                            view.setVisibility(0);
                                            view.invalidate();
                                        }
                                    }
                                });
                            }
                        }
                    });
                }
            };
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction("android.intent.action.SCREEN_OFF");
            INVOKEVIRTUAL_com_he_lynx_HeliumApp_com_bytedance_sysoptimizer_ReceiverRegisterLancet_registerReceiver(this.context, this.screenReceiver, intentFilter);
        }
        if (surfaceHolder == null) {
            surfaceHolder = new TextureViewHolder(textureView);
        }
        return addViewInternal(textureView, surfaceHolder);
    }

    private Drawable addViewInternal(View view, SurfaceHolder surfaceHolder) {
        MethodCollector.i(8544);
        Surface surface = getSurface(surfaceHolder);
        if (surface != null) {
            long j = this.ptr;
            if (j != 0) {
                long addView = Helium.addView(j, surface);
                if (addView != 0) {
                    Drawable createDrawable = createDrawable(addView, view, surfaceHolder);
                    MethodCollector.o(8544);
                    return createDrawable;
                }
                RuntimeException runtimeException = new RuntimeException("failed to create EGLSurface");
                MethodCollector.o(8544);
                throw runtimeException;
            }
            RuntimeException runtimeException2 = new RuntimeException("heliumAppPtr is null");
            MethodCollector.o(8544);
            throw runtimeException2;
        }
        RuntimeException runtimeException3 = new RuntimeException("surface is null");
        MethodCollector.o(8544);
        throw runtimeException3;
    }

    public final void dispatch(Drawable drawable, MotionEvent motionEvent) {
        LynxDelegate lynxDelegate2 = (LynxDelegate) this.lynxDelegate.get();
        if (lynxDelegate2 != null) {
            int actionIndex = motionEvent.getActionIndex();
            int i = 5;
            if (actionIndex < 5) {
                int pointerCount = motionEvent.getPointerCount();
                if (pointerCount <= 5) {
                    i = pointerCount;
                }
                final ByteBuffer allocateDirect = ByteBuffer.allocateDirect(112);
                allocateDirect.order(ByteOrder.LITTLE_ENDIAN);
                allocateDirect.clear();
                allocateDirect.put((byte) 1);
                allocateDirect.put((byte) motionEvent.getActionMasked());
                allocateDirect.put((byte) i);
                allocateDirect.put((byte) actionIndex);
                float rawX = motionEvent.getRawX() - motionEvent.getX();
                float rawY = motionEvent.getRawY() - motionEvent.getY();
                for (int i2 = 0; i2 < i; i2++) {
                    allocateDirect.putInt(motionEvent.getPointerId(i2));
                    allocateDirect.putFloat(motionEvent.getX(i2));
                    allocateDirect.putFloat(motionEvent.getY(i2));
                    allocateDirect.putFloat(motionEvent.getX(i2) + rawX);
                    allocateDirect.putFloat(motionEvent.getY(i2) + rawY);
                }
                allocateDirect.putLong(104, drawable.ptr);
                lynxDelegate2.runOnJsThread(new Runnable() {
                    static {
                        Covode.recordClassIndex(45638);
                    }

                    public void run() {
                        MethodCollector.i(6837);
                        Helium.dispatch(HeliumApp.this.ptr, allocateDirect);
                        MethodCollector.o(6837);
                    }
                });
            }
        }
    }

    private Drawable createDrawable(long j, View view, SurfaceHolder surfaceHolder) {
        Drawable drawable = new Drawable(j, view, surfaceHolder);
        this.drawables.add(drawable);
        if (view != null) {
            view.setOnTouchListener(this.delegate);
        }
        surfaceHolder.addCallback(this.delegate);
        return drawable;
    }

    public static Intent INVOKEVIRTUAL_com_he_lynx_HeliumApp_com_bytedance_sysoptimizer_ReceiverRegisterLancet_registerReceiver(ContextWrapper contextWrapper, BroadcastReceiver broadcastReceiver, IntentFilter intentFilter) {
        if (ReceiverRegisterCrashOptimizer.fixedOpen()) {
            ReceiverRegisterCrashOptimizer.doHWReceiverFix();
        }
        try {
            if (ReceiverRegisterCrashOptimizer.doRegisterHandler()) {
                return contextWrapper.registerReceiver(broadcastReceiver, intentFilter, (String) null, ReceiverRegisterLancet.sReceiverHandler);
            }
            return contextWrapper.registerReceiver(broadcastReceiver, intentFilter);
        } catch (Exception e) {
            if (ReceiverRegisterCrashOptimizer.fixedOpen()) {
                return ReceiverRegisterCrashOptimizer.registerReceiver(broadcastReceiver, intentFilter);
            }
            throw e;
        }
    }
}
