Question

The following code works fine when running from java command line. However when running using exec:java I never see that line printed...Anyway to stop this behaviour?

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);
}
Was it helpful?

Solution

My assumption is that the default UncaughtExceptionHandler is overridden by Maven itself.

From the usage guide:

Note: The java goal doesn't spawn a new process [...] Otherwise consider using the exec goal.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top