001    package com.github.sarxos.webcam;
002    
003    import java.lang.Thread.UncaughtExceptionHandler;
004    
005    import org.slf4j.Logger;
006    import org.slf4j.LoggerFactory;
007    
008    
009    /**
010     * Used internally.
011     * 
012     * @author Bartosz Firyn (sarxos)
013     */
014    public class WebcamExceptionHandler implements UncaughtExceptionHandler {
015    
016            private static final Logger LOG = LoggerFactory.getLogger(WebcamExceptionHandler.class);
017    
018            private static final WebcamExceptionHandler INSTANCE = new WebcamExceptionHandler();
019    
020            private WebcamExceptionHandler() {
021                    // singleton
022            }
023    
024            @Override
025            public void uncaughtException(Thread t, Throwable e) {
026                    LOG.error(String.format("Exception in thread %s", t.getName()), e);
027                    System.err.println(String.format("Exception in thread %s", t.getName()));
028                    e.printStackTrace();
029            }
030    
031            public static final WebcamExceptionHandler getInstance() {
032                    return INSTANCE;
033            }
034    }