class Solution { public static void main(String[] args) throws InterruptedException { ExecutorService executorService = Executors.newFixedThreadPool(1); Future<Integer> future = executorService.submit(() -> { try{ System.out.println("Start"); Thread.sleep(1000); } catch (InterruptedException e) { throw new InterruptedException(); } Random random = new Random(); int randomValue = random.nextInt(10); if(randomValue > 5){ throw new Exception(); // 19 line } return randomValue; }); executorService.shutdown(); try{ int value = future.get(); System.out.println(value); } catch (InterruptedException e){ System.out.println("Thread was interrupted"); } catch (ExecutionException e) { Throwable ex = e.getCause(); System.out.println(ex.getMessage()); } catch (Exception e) { System.out.println("g"); } } }