本文整理了Java中java.lang.Thread.getDefaultUncaughtExceptionHandler()
方法的一些代码示例,展示了Thread.getDefaultUncaughtExceptionHandler()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Thread.getDefaultUncaughtExceptionHandler()
方法的具体详情如下:
包路径:java.lang.Thread
类名称:Thread
方法名:getDefaultUncaughtExceptionHandler
[英]Returns the default handler invoked when a thread abruptly terminates due to an uncaught exception. If the returned value is null, there is no default.
[中]返回由于未捕获异常导致线程突然终止时调用的默认处理程序。如果返回值为null,则不存在默认值。
代码示例来源:origin: aa112901/remusic
public UnceHandler(MainApplication application) {
//获取系统默认的UncaughtException处理器
mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
this.application = application;
}
代码示例来源:origin: stackoverflow.com
if(!(Thread.getDefaultUncaughtExceptionHandler() instanceof CustomExceptionHandler)) {
Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(
"/sdcard/<desired_local_path>", "http://<desired_url>/upload.php"));
}
代码示例来源:origin: smuyyh/BookReader
/**
* 初始化
*
* @param context
*/
public void init(Context context) {
mContext = context;
//获取系统默认的UncaughtException处理器
mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
//设置该CrashHandler为程序的默认处理器
Thread.setDefaultUncaughtExceptionHandler(this);
}
代码示例来源:origin: iSoron/uhabits
public BaseExceptionHandler(@NonNull BaseActivity activity)
{
this.activity = activity;
originalHandler = Thread.getDefaultUncaughtExceptionHandler();
}
代码示例来源:origin: apache/hive
@Override
public void onFailure(Throwable t) {
LOG.error("Wait queue scheduler worker exited with failure!", t);
Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), t);
}
}
代码示例来源:origin: Rukey7/MvpApp
public void init(Context context) {
mDefaultCrashHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(this);
mContext = context.getApplicationContext();
}
代码示例来源:origin: Tencent/tinker
public TinkerUncaughtHandler(Context context) {
this.context = context;
ueh = Thread.getDefaultUncaughtExceptionHandler();
crashFile = SharePatchFileUtil.getPatchLastCrashFile(context);
}
代码示例来源:origin: square/okhttp
@Override public void testRunStarted(Description description) {
System.err.println("Installing aggressive uncaught exception handler");
oldDefaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> {
StringWriter errorText = new StringWriter(256);
errorText.append("Uncaught exception in OkHttp thread \"");
errorText.append(thread.getName());
errorText.append("\"\n");
throwable.printStackTrace(new PrintWriter(errorText));
errorText.append("\n");
if (lastTestStarted != null) {
errorText.append("Last test to start was: ");
errorText.append(lastTestStarted.getDisplayName());
errorText.append("\n");
}
System.err.print(errorText.toString());
synchronized (exceptions) {
exceptions.put(throwable, lastTestStarted.getDisplayName());
}
});
}
代码示例来源:origin: apache/hive
@Override
public void onFailure(Throwable t) {
if (t instanceof CancellationException && isShutdown.get()) {
LOG.info("AMReporter QueueDrainer exited as a result of a cancellation after shutdown");
} else {
LOG.error("AMReporter QueueDrainer exited with error", t);
Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), t);
}
}
});
代码示例来源:origin: oracle/opengrok
public static void registerErrorHandler() {
UncaughtExceptionHandler dueh =
Thread.getDefaultUncaughtExceptionHandler();
if (dueh == null) {
LOGGER.log(Level.FINE, "Installing default uncaught exception handler");
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
LOGGER.log(Level.SEVERE, "Uncaught exception in thread "
+ t.getName() + " with ID " + t.getId() + ": "
+ e.getMessage(), e);
}
});
}
}
}
代码示例来源:origin: apache/hive
private void insertIntoPreemptionQueueOrFailUnlocked(TaskWrapper taskWrapper) {
boolean added = preemptionQueue.offer(taskWrapper);
if (!added) {
LOG.warn("Failed to add element {} to preemption queue. Terminating", taskWrapper);
Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(),
new IllegalStateException("Preemption queue full. Cannot proceed"));
}
}
代码示例来源:origin: apache/hive
@Override
public void onSuccess(Object result) {
if (isShutdown.get()) {
LOG.info("Wait queue scheduler worker exited with success!");
} else {
LOG.error("Wait queue scheduler worker exited with success!");
Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(),
new IllegalStateException("WaitQueue worked exited before shutdown"));
}
}
代码示例来源:origin: lealone/Lealone
/**
* Send @param t to the default uncaught exception handler, or log it if none such is set up
*/
public static void handleOrLog(Throwable t) {
if (Thread.getDefaultUncaughtExceptionHandler() == null)
logger.error("Error in ThreadPoolExecutor", t);
else
Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), t);
}
代码示例来源:origin: twitter/distributedlog
/**
* The executor re-throws exceptions thrown by the task to the uncaught exception handler
* so we only need to do anything if uncaught exception handler has not been se
*/
private void logAndHandle(Throwable t, boolean passToHandler) {
if (Thread.getDefaultUncaughtExceptionHandler() == null) {
LOG.error("Unhandled exception on thread {}", Thread.currentThread().getName(), t);
}
else {
LOG.info("Unhandled exception on thread {}", Thread.currentThread().getName(), t);
if (passToHandler) {
Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), t);
}
}
}
代码示例来源:origin: ankidroid/Anki-Android
/**
* We want to send an analytics hit on any exception, then chain to other handlers (e.g., ACRA)
*/
synchronized private static void installDefaultExceptionHandler() {
sOriginalUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> {
sendAnalyticsException(throwable, true);
sOriginalUncaughtExceptionHandler.uncaughtException(thread, throwable);
});
}
代码示例来源:origin: koral--/android-gif-drawable
@Override
public final void run() {
try {
if (!mGifDrawable.isRecycled()) {
doWork();
}
} catch (Throwable throwable) {
final Thread.UncaughtExceptionHandler uncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
if (uncaughtExceptionHandler != null) {
uncaughtExceptionHandler.uncaughtException(Thread.currentThread(), throwable);
}
throw throwable;
}
}
代码示例来源:origin: spotify/helios
@Before
public void setup() throws Exception {
zk = new ZooKeeperTestingServerManager();
dueh = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(final Thread thread, final Throwable th) {}
});
stateDir = Files.createTempDirectory("helios-agent-conflict-test");
first = makeAgent("first");
second = makeAgent("second");
}
代码示例来源:origin: ReactiveX/RxJava
Thread.UncaughtExceptionHandler originalHandler = Thread.getDefaultUncaughtExceptionHandler();
try {
CapturingUncaughtExceptionHandler handler = new CapturingUncaughtExceptionHandler();
代码示例来源:origin: ReactiveX/RxJava
private static void expectUncaughtTestException(Action action) {
Thread.UncaughtExceptionHandler originalHandler = Thread.getDefaultUncaughtExceptionHandler();
CapturingUncaughtExceptionHandler handler = new CapturingUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(handler);
RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
@Override
public void accept(Throwable error) throws Exception {
Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), error);
}
});
try {
action.run();
assertEquals("Should have received exactly 1 exception", 1, handler.count);
Throwable caught = handler.caught;
while (caught != null) {
if (caught instanceof TestException) { break; }
if (caught == caught.getCause()) { break; }
caught = caught.getCause();
}
assertTrue("A TestException should have been delivered to the handler",
caught instanceof TestException);
} catch (Throwable ex) {
throw ExceptionHelper.wrapOrThrow(ex);
} finally {
Thread.setDefaultUncaughtExceptionHandler(originalHandler);
RxJavaPlugins.setErrorHandler(null);
}
}
代码示例来源:origin: ReactiveX/RxJava
Thread.UncaughtExceptionHandler originalHandler = Thread.getDefaultUncaughtExceptionHandler();
try {
CapturingUncaughtExceptionHandler handler = new CapturingUncaughtExceptionHandler();
内容来源于网络,如有侵权,请联系作者删除!