package codeine;

import java.lang.Thread.UncaughtExceptionHandler;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

public class CodeineUncaughtExceptionHandler implements UncaughtExceptionHandler {

	private Logger log = Logger.getLogger(CodeineUncaughtExceptionHandler.class);

	private boolean errorPrintedToOut = false;

	public CodeineUncaughtExceptionHandler() {
	}

	@Override
	public void uncaughtException(Thread t, Throwable e) {
		try {
			System.out.println("Uncaught exception!");
			if (!errorPrintedToOut) {
				errorPrintedToOut = true;
				e.printStackTrace();
			}
			log.error("Uncaught exception in thread " + t.getName(), e);
		} catch (Throwable tr) {
			try {
				e.printStackTrace();
				tr.printStackTrace();
			} catch (Throwable e1) {
				log.fatal("could not write stacktrace of exception " + t.getName());
				addExceptionInfo(e1);
				addExceptionInfo(e);
				addExceptionInfo(tr);
			}
		}
	}

	private void addExceptionInfo(Throwable e) {
		log.fatal("exception info " + e.getMessage() + " " + e);
	}

	public static void main(String[] args) {
		
	}
	public static void main1(String[] args) {
		BasicConfigurator.configure();
		Thread.setDefaultUncaughtExceptionHandler(new CodeineUncaughtExceptionHandler());
		throw new RuntimeException() {
			private static final long serialVersionUID = 1L;

			@Override
			public void printStackTrace(java.io.PrintWriter s) {
				overflow();

			}

			@Override
			public void printStackTrace() {
				overflow();
			}

			private void overflow() {
				overflow();
			}

		};
	}

}
@@ -1043,25 +1043,17 @@
 ge()
- + %22 %22 + e
 );%0A%09%7D%0A%0A
+//
 %09pub
@@ -1094,14 +1094,18 @@
 ) %7B%0A
-%09%09%0A
+//%0A//
 %09%7D%0A
+//
 %09pub
@@ -1124,17 +1124,16 @@
 oid main
-1
 (String%5B
@@ -1142,16 +1142,18 @@
 args) %7B%0A
+//
 %09%09BasicC
@@ -1177,16 +1177,18 @@
 gure();%0A
+//
 %09%09Thread
@@ -1263,16 +1263,18 @@
 ler());%0A
+//
 %09%09throw 
@@ -1298,16 +1298,18 @@
 ion() %7B%0A
+//
 %09%09%09priva
@@ -1352,17 +1352,21 @@
 D = 1L;%0A
-%0A
+//%0A//
 %09%09%09@Over
@@ -1362,32 +1362,128 @@
 %0A//%09%09%09@Override%0A
+//%09%09%09public String getMessage() %7B%0A//%09%09%09%09overflow();%0A//%09%09%09%09return %22%22;%0A//%09%09%09%7D%0A//%0A//%09%09%09@Override%0A//
 %09%09%09public void p
@@ -1518,24 +1518,26 @@
 Writer s) %7B%0A
+//
 %09%09%09%09overflow
@@ -1540,23 +1540,28 @@
 flow();%0A
-%0A
+//
 %09%09%09%7D%0A
-%0A
+//%0A//
 %09%09%09@Over
@@ -1565,16 +1565,18 @@
 verride%0A
+//
 %09%09%09publi
@@ -1598,24 +1598,26 @@
 ckTrace() %7B%0A
+//
 %09%09%09%09overflow
@@ -1620,22 +1620,28 @@
 flow();%0A
+//
 %09%09%09%7D%0A
-%0A
+//%0A//
 %09%09%09priva
@@ -1657,24 +1657,26 @@
 verflow() %7B%0A
+//
 %09%09%09%09overflow
@@ -1683,19 +1683,27 @@
 ();%0A
+//
 %09%09%09%7D%0A
-%0A
+//%0A//
 %09%09%7D;%0A
+//
 %09%7D%0A%0A

Remove exception printing from log to avoid stack overflow