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  .  java 2 s .c o  m

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

Result

Related Topic