You have several options to handle exceptions thrown by threads. One is to have a general uncaught exceptions handler:
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { //log the exception or handle it here if possible } });
But it is difficult to link an exception caught that way with a specific thread.
Or you can use an ExecutorService instead of starting the thread manually:
ExecutorService executor = Executors.newCachedThreadPool(); Future<?> future = executor.submit(new Runnable() { @Override public void run() { throw new RuntimeException("Some exception"); } }); try { future.get(); } catch (ExecutionException e) { Throwable yourException = e.getCause(); //here you can access the exception }
new Thread()and.start()are not likely to throw an exception. Then a parallel thread is startend andruncalled. Via an exception handler you can be informed.