从java命令行运行时,以下代码可以正常工作。但是当使用exec:java运行时,我从未看到打印过这行...无论如何要阻止这种行为?
public static void main(String[] args) throws InterruptedException {
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
System.out.println("Uncaught exception: " + e.getMessage());
}
});
Executors.newSingleThreadExecutor().execute(new Runnable() {
@Override
public void run() {
int i = 1 / 0;
}
});
Thread.sleep(1000);
System.exit(0);
}
答案 0 :(得分:2)