1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-26 20:06:52 +01:00
Gadgetbridge/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/LoggingExceptionHandler.java
2015-10-26 23:32:03 +01:00

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);
}
}
}