diff --git a/pocketfft_hdronly.h b/pocketfft_hdronly.h
index b5387530f38129427148daff619281c55c5267c1..6c549def9ff734135fafa8dd48338750a211b956 100644
--- a/pocketfft_hdronly.h
+++ b/pocketfft_hdronly.h
@@ -742,17 +742,26 @@ void thread_map(size_t nthreads, Func f)
 
   auto & pool = get_pool();
   latch counter(nthreads);
+  exception_ptr ex;
+  mutex ex_mut;
   for (size_t i=0; i<nthreads; ++i)
     {
     pool.submit(
-      [&f, &counter, i, nthreads] {
+      [&f, &counter, &ex, &ex_mut, i, nthreads] {
       thread_id = i;
       num_threads = nthreads;
-      f();
+      try { f(); }
+      catch (...)
+        {
+        lock_guard<mutex> lock(ex_mut);
+        ex = current_exception();
+        }
       counter.count_down();
       });
     }
   counter.wait();
+  if (ex)
+    rethrow_exception(ex);
   }
 }