package de.htw.vs.shell;

import org.apache.log4j.Logger;

import java.lang.Thread.UncaughtExceptionHandler;

public class UncaughtExceptionLogger implements UncaughtExceptionHandler {

	@Override
	public void uncaughtException(Thread t, Throwable ex) {
		 if (! (ex instanceof ThreadDeath)) {
			 logException(t, ex);
		 }
	}

	private void logException(Thread t, Throwable ex) {
		String errorMessage = String.format("Exception in thread '%s'",t);
		Logger.getLogger(getNameOfClassWhichThrowed(ex)).error(errorMessage, ex);
	}

	private String getNameOfClassWhichThrowed(Throwable ex) {
		StackTraceElement[] stacktrace = ex.getStackTrace();
		return  stacktrace.length > 0 ? stacktrace[0].getClassName() : "Unknown" ;
	}

}

@@ -103,16 +103,114 @@
 ndler;%0A%0A
+/**%0A * An %7B@link UncaughtExceptionHandler%7D which logs all uncaught exceptions%0A * to a Logger.%0A */%0A
 public c

Add doc comments for the UncaughtExceptionLogger