GreyTeardrop
7/27/2011 - 9:07 PM

UncaughtExceptionLogger.java

…
public static void main(String[] args) {
	Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionLogger());
…
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.lang.Thread.UncaughtExceptionHandler;

/**
 * Простейший перехватчик исключений для записи в лог
 */
public class UncaughtExceptionLogger implements UncaughtExceptionHandler {
	@Override
	public void uncaughtException(Thread t, Throwable e) {
		try {
			PrintWriter writer = new PrintWriter(new File("Notie_exception.log")));
			e.printStackTrace(writer);
		} catch (FileNotFoundException ignored) {
		} finally {
			writer.close();
		}
	}
}