Java - Handling Uncaught Exceptions in a Task Execution

Description

Handling Uncaught Exceptions in a Task Execution

Demo

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Main {
        public static void main(String[] args) {
                Runnable badTask = () -> {
                        throw new RuntimeException("Throwing exception from task execution...");
                };//from w  w w .ja  v a 2s .c  o  m

                ExecutorService exec = Executors.newSingleThreadExecutor();
                exec.execute(badTask);
                exec.shutdown();
        }
}

Result

Related Topic