From 07242f27323406e526b91b3387f1a06fda61b3a2 Mon Sep 17 00:00:00 2001
From: bangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Date: Mon, 3 Jun 2013 04:25:55 +0000
Subject: [PATCH] Catch exceptions also in WorkStream, similar to the recent
 change to tasks.

git-svn-id: https://svn.dealii.org/trunk@29734 0785d39b-7218-0410-832d-ea1e28bc413d
---
 deal.II/include/deal.II/base/work_stream.h | 50 +++++++++++++++++-----
 1 file changed, 40 insertions(+), 10 deletions(-)

diff --git a/deal.II/include/deal.II/base/work_stream.h b/deal.II/include/deal.II/base/work_stream.h
index b44ed33f2c..e43b43554e 100644
--- a/deal.II/include/deal.II/base/work_stream.h
+++ b/deal.II/include/deal.II/base/work_stream.h
@@ -1,7 +1,7 @@
 //---------------------------------------------------------------------------
 //    $Id$
 //
-//    Copyright (C) 2008, 2009, 2010, 2012 by the deal.II authors
+//    Copyright (C) 2008, 2009, 2010, 2012, 2013 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -344,14 +344,28 @@ namespace WorkStream
 
         ItemType *current_item = static_cast<ItemType *> (item);
 
-        // then call the worker function on
-        // each element of the chunk we
-        // were given
+        // then call the worker function on each element of the chunk we were
+        // given. since these worker functions are called on separate threads,
+        // nothing good can happen if they throw an exception and we are best
+        // off catching it and showing an error message
         for (unsigned int i=0; i<std_cxx1x::get<3>(*current_item); ++i)
-          worker (std_cxx1x::get<0>(*current_item)[i],
-                  *std_cxx1x::get<1>(*current_item),
-                  std_cxx1x::get<2>(*current_item)[i]);
-
+	  {
+	    try
+	      {
+		worker (std_cxx1x::get<0>(*current_item)[i],
+			*std_cxx1x::get<1>(*current_item),
+			std_cxx1x::get<2>(*current_item)[i]);
+	      }
+	    catch (const std::exception &exc)
+	      {
+		internal::handle_std_exception (exc);
+	      }
+	    catch (...)
+	      {
+		internal::handle_unknown_exception ();
+	      }
+	  }
+	
         // then return the original pointer
         // to the now modified object
         return item;
@@ -415,9 +429,25 @@ namespace WorkStream
 
         ItemType *current_item = static_cast<ItemType *> (item);
 
-        // initiate copying data
+        // initiate copying data. for the same reasons as in the worker class
+        // above, catch exceptions rather than letting it propagate into
+        // unknown territories
         for (unsigned int i=0; i<std_cxx1x::get<3>(*current_item); ++i)
-          copier (std_cxx1x::get<2>(*current_item)[i]);
+	  {
+	    try
+	      {
+		copier (std_cxx1x::get<2>(*current_item)[i]);
+	      }
+	    catch (const std::exception &exc)
+	      {
+		internal::handle_std_exception (exc);
+	      }
+	    catch (...)
+	      {
+		internal::handle_unknown_exception ();
+	      }
+	  }
+	
 
         // return an invalid
         // item since we are at
-- 
2.39.5