Java Thread.currentThread().setUncaughtExceptionHandler() not working with JUNIT?
问题 In the example code below, if the testMethod() is run via main() it works as expected but if it is run via JUNIT then MyUncaughtExceptionHandler does not get called. Is there some explanation for this? package nz.co.test; import java.lang.Thread.UncaughtExceptionHandler; import org.junit.Test; public class ThreadDemo { private void testMethod() { Thread.currentThread().setUncaughtExceptionHandler(new MyUncaughtExceptionHandler()); Object b = null; // Cause a NPE b.hashCode(); } @Test public