mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-05 01:37:03 +01:00
28 lines
837 B
Java
28 lines
837 B
Java
package nodomain.freeyourgadget.gadgetbridge;
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
/**
|
|
* Catches otherwise uncaught exceptions, logs them and terminates the app.
|
|
*/
|
|
public class LoggingExceptionHandler implements Thread.UncaughtExceptionHandler {
|
|
private static final Logger LOG = LoggerFactory.getLogger(LoggingExceptionHandler.class);
|
|
private final Thread.UncaughtExceptionHandler mDelegate;
|
|
|
|
public LoggingExceptionHandler(Thread.UncaughtExceptionHandler delegate) {
|
|
mDelegate = delegate;
|
|
}
|
|
|
|
@Override
|
|
public void uncaughtException(Thread thread, Throwable ex) {
|
|
LOG.error("Uncaught exception: " + ex.getMessage(), ex);
|
|
if (mDelegate != null) {
|
|
mDelegate.uncaughtException(thread, ex);
|
|
} else {
|
|
System.exit(1);
|
|
}
|
|
}
|
|
}
|