Here you can find the source of getExceptionFromNewThread(String threadName, Runnable target)
public static Throwable getExceptionFromNewThread(String threadName, Runnable target)
//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 {// w w w . j ava 2s. c o m 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(); } } }