Java tutorial
//package com.java2s; // This software is released under the Apache License 2.0. import java.util.concurrent.*; public class Main { public static Throwable getExceptionFromNewThread(String threadName, Runnable target) { try { runInNewThread(threadName, target); } catch (Throwable throwable) { return throwable; } throw new AssertionError("Expected to throw an exception but did not throw anything"); } public static void runInNewThread(String threadName, Runnable target) throws Throwable { FutureTask<Object> future = new FutureTask<Object>(target, null); new Thread(future, threadName).start(); try { future.get(); } catch (ExecutionException e) { throw e.getCause(); } } }