com.github.sarxos.webcam.WebcamExceptionHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of webcam-capture Show documentation
Show all versions of webcam-capture Show documentation
This library allows you to use your PC webcam, IP or network cameras directly from Java. It's compatible with most operating systems (Windows, Linux, MacOS).
package com.github.sarxos.webcam;
import java.lang.Thread.UncaughtExceptionHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.helpers.NOPLoggerFactory;
/**
* Used internally.
*
* @author Bartosz Firyn (sarxos)
*/
public class WebcamExceptionHandler implements UncaughtExceptionHandler {
private static final Logger LOG = LoggerFactory.getLogger(WebcamExceptionHandler.class);
private static final WebcamExceptionHandler INSTANCE = new WebcamExceptionHandler();
private WebcamExceptionHandler() {
// singleton
}
@Override
public void uncaughtException(Thread t, Throwable e) {
Object context = LoggerFactory.getILoggerFactory();
if (context instanceof NOPLoggerFactory) {
System.err.println(String.format("Exception in thread %s", t.getName()));
e.printStackTrace();
} else {
LOG.error(String.format("Exception in thread %s", t.getName()), e);
}
}
public static void handle(Throwable e) {
INSTANCE.uncaughtException(Thread.currentThread(), e);
}
public static final WebcamExceptionHandler getInstance() {
return INSTANCE;
}
}