Q:

How to avoid thread in threadpool dead when exception thrown without try catch

My code looks like this:
public class ExceptionTest {
    public static Logger log = LoggerFactory.getLogger(ExceptionTest.class);
    public final static ThreadFactory factory = new ThreadFactory() {
        @Override
        public Thread newThread(Runnable target) {
            final Thread thread = new Thread(target);
            log.debug("Creating new worker thread");
            thread.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
                @Override
                public void uncaughtException(Thread t, Throwable e) {
                    log.error("Uncaught Exception", e);
                }
            });
            return thread;
        }

    };
    final static ExecutorService executor = Executors.newCachedThreadPool(factory);
    public static void main(String[] args) {
        executor.execute(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    System.out.println(Thread.currentThread().getName());
                    int i = 1;
                    int j = 0;
                    System.out.println(i / j);
                }
            }
        });
    }

}

The console only print the message one time. This means the thread has died. Is there any other way to prevent thread death (except try catch block, this is much repeated code).

A:

No, you can not achieve this without using try...catch block, see jls:

If no catch clause that can handle an exception can be found, then the
  current thread (the thread that encountered the exception) is
  terminated.

And, I do not think the termination of threads in a cached thread pool is a problem, since next time you submit a new task, a new thread will be created to handle it.

If it really matters, and you do not want repeated code, you can write a wrapper class like this:
public class WrapperRunnable implements Runnable {

    Runnable runnable;

    public WrapperRunnable(Runnable runnable) {
        this.runnable = runnable;
    }

    @Override
    public void run() {
        while (true) {
            try {
                runnable.run();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

And submit WrapperRunnable to executor:
Runnable runnable = new Runnable() {
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName());
        int i = 1;
        int j = 0;
        System.out.println(i / j);
    }
};
WrapperRunnable wrapperRunnable = new WrapperRunnable(runnable);
executor.execute(wrapperRunnable);

