2 Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef DCPOMATIC_EXCEPTION_STORE_H
22 #define DCPOMATIC_EXCEPTION_STORE_H
24 #include <boost/exception/all.hpp>
25 #include <boost/thread/mutex.hpp>
27 /** @class ExceptionStore
28 * @brief A parent class for classes which have a need to catch and
29 * re-throw exceptions.
31 * This is intended for classes which run their own thread; they should do
36 * // do things which might throw exceptions
41 * and then in another thread call rethrow(). If any
42 * exception was thrown by my_thread it will be stored by
43 * store_current() and then rethrow() will re-throw it where
50 boost::mutex::scoped_lock lm (_exception_mutex);
52 boost::exception_ptr tmp = _exception;
53 _exception = boost::exception_ptr ();
54 boost::rethrow_exception (tmp);
60 void store_current () {
61 boost::mutex::scoped_lock lm (_exception_mutex);
62 _exception = boost::current_exception ();
66 boost::exception_ptr _exception;
67 mutable boost::mutex _exception_mutex;