public class Apple {@Overrideprotected void finalize() throws Throwable {super.finalize();Thread.sleep(130*1000);}
}
在 actvitity 中创建一个A pple 对象。
C rash Handler里拦截异常
import android.util.Log;import androidx.annotation.NonNull;import java.util.concurrent.TimeoutException;public class Te implements Thread.UncaughtExceptionHandler {@Overridepublic void uncaughtException(@NonNull Thread thread, @NonNull Throwable ex) {if (thread.getName().equals("FinalizerWatchdogDaemon") && (ex instanceof TimeoutException || ex.getMessage().contains("timed out"))) {return; //Ignore}}
}
会报两个异常,分别是RuntimeException 和 TimeoutException
uncaughtException thread.getName FinalizerWatchdogDaemon## ex.getMessage(.Apple.finalize() timed out after 10 seconds## ex.getClass().getName()java.util.concurrent.TimeoutException
uncaughtException thread.getName FinalizerWatchdogDaemon## ex.getMessage(java.util.concurrent.TimeoutException: .Apple.finalize() timed out after 10 seconds## ex.getClass().getName()java.lang.RuntimeException