Skip to content
Snippets Groups Projects
Commit 2bda4ac9 authored by Dr. Felix Tobias Schindler's avatar Dr. Felix Tobias Schindler
Browse files

[exceptions] add handling of tbb/boost/std exceptions

Not sure about the boost case, however...
parent 9381d0aa
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@
#include <boost/numeric/conversion/cast.hpp>
#include <dune/xt/common/exceptions.hh>
#include <dune/xt/common/exceptions.bindings.hh>
#include <dune/common/parallel/mpihelper.hh>
......@@ -30,7 +30,7 @@
#include <dune/xt/common/string.hh>
#include <dune/xt/common/timedlogging.hh>
#include "exceptions.pbh"
#include "exceptions.bindings.hh"
#include "fvector.pbh"
#include "fmatrix.pbh"
#include "configuration.pbh"
......@@ -43,7 +43,7 @@ PYBIND11_PLUGIN(_common)
py::module m("_common", "dune-xt-common");
Dune::XT::Common::bind_Exception(m);
Dune::XT::Common::bindings::addbind_exceptions(m);
m.def("_init_mpi",
[](const std::vector<std::string>& args) {
......
......@@ -7,12 +7,18 @@
// Authors:
// Felix Schindler (2016 - 2017)
#ifndef DUNE_XT_COMMON_EXCEPTIONS_PBH
#define DUNE_XT_COMMON_EXCEPTIONS_PBH
#ifndef DUNE_XT_COMMON_EXCEPTIONS_BINDINGS_HH
#define DUNE_XT_COMMON_EXCEPTIONS_BINDINGS_HH
#if HAVE_DUNE_PYBINDXI
#include <string>
#include <boost/exception/all.hpp>
#if HAVE_TBB
#include <tbb/tbb_exception.h>
#endif
#include <dune/pybindxi/pybind11.h>
#include "exceptions.hh"
......@@ -20,29 +26,43 @@
namespace Dune {
namespace XT {
namespace Common {
namespace bindings {
void bind_Exception(pybind11::module& m)
void addbind_exceptions(pybind11::module& m)
{
namespace py = pybind11;
static py::exception<Exception> exc(m, "DuneError");
static py::exception<std::exception> std_exc(m, "StdError");
#if HAVE_TBB
static py::exception<tbb::tbb_exception> tbb_exc(m, "TbbError");
#endif
static py::exception<boost::exception> boost_exc(m, "BoostError");
static py::exception<Dune::Exception> dune_exc(m, "DuneError");
py::register_exception_translator([](std::exception_ptr p) {
try {
if (p)
std::rethrow_exception(p);
} catch (const Exception& e) {
exc(std::string(e.what()).c_str());
} catch (const boost::exception& e) {
boost_exc(boost::diagnostic_information_what(e));
} catch (const Dune::Exception& e) {
dune_exc(e.what());
#if HAVE_TBB
} catch (const tbb::tbb_exception& e) {
tbb_exc(std::string(e.name() + ": " + e.what()).c_str());
#endif
} catch (const std::exception& e) {
std_exc(e.what());
}
});
} // ... bind_Exception(...)
} // ... addbind_exceptions(...)
} // namespace bindings
} // namespace Common
} // namespace XT
} // namespace Dune
#endif // HAVE_DUNE_PYBINDXI
#endif // DUNE_XT_COMMON_EXCEPTIONS_PBH
#endif // DUNE_XT_COMMON_EXCEPTIONS_BINDINGS_HH
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment