Add uncaught exception handler

This commit is contained in:
Chris Eager
2021-08-11 18:04:24 -05:00
committed by Chris Eager
parent 57a478b898
commit de59aa099d
2 changed files with 31 additions and 1 deletions

View File

@@ -0,0 +1,27 @@
/*
* Copyright 2021 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.textsecuregcm.util.logging;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class UncaughtExceptionHandler {
private static final Logger logger = LoggerFactory.getLogger(UncaughtExceptionHandler.class);
public static void register() {
@Nullable final Thread.UncaughtExceptionHandler current = Thread.getDefaultUncaughtExceptionHandler();
if (current != null) {
logger.warn("Uncaught exception handler already exists: {}", current);
return;
}
Thread.setDefaultUncaughtExceptionHandler((t, e) -> logger.error("Uncaught exception on thread {}", t, e));
}
}