Skip to content
Snippets Groups Projects
Commit 69b99c59 authored by Felix Schindler's avatar Felix Schindler
Browse files

[common.exceptions]

* give mpi info in parallel runs
* overwrite DUNE_THROW
parent 97d061ec
No related branches found
No related tags found
No related merge requests found
...@@ -7,8 +7,7 @@ ...@@ -7,8 +7,7 @@
#define DUNE_STUFF_COMMON_EXCEPTIONS_HH #define DUNE_STUFF_COMMON_EXCEPTIONS_HH
#include <dune/common/exceptions.hh> #include <dune/common/exceptions.hh>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/stuff/common/color.hh>
/** /**
* \brief Macro to throw a colorfull exception. * \brief Macro to throw a colorfull exception.
...@@ -28,22 +27,32 @@ if (a.size() != b.size()) ...@@ -28,22 +27,32 @@ if (a.size() != b.size())
*/ */
#define DUNE_THROW_COLORFULLY(E, m) \ #define DUNE_THROW_COLORFULLY(E, m) \
do { \ do { \
const std::string red = "\033[31m"; \
const std::string clear = "\033[0m"; \
E th__ex; \ E th__ex; \
std::ostringstream th__msg; \ std::ostringstream th__msg; \
th__msg << m; \ th__msg << m; \
std::ostringstream th__out; \ std::ostringstream th__out; \
th__out << Dune::Stuff::Common::Colors::red << #E << "\033[0m\n"; \ th__out << red << #E << clear; \
th__out << Dune::Stuff::Common::Colors::red << "[\033[0m"; \ if (Dune::MPIHelper::getCollectiveCommunication().size() > 0) \
th__out << " (on rank " << Dune::MPIHelper::getCollectiveCommunication().rank() << ")"; \
th__out << "\n"; \
th__out << red << "[" << clear; \
th__out << __func__; \ th__out << __func__; \
th__out << Dune::Stuff::Common::Colors::red << "|\033[0m"; \ th__out << red << "|" << clear; \
th__out << __FILE__ << Dune::Stuff::Common::Colors::red << ":" << __LINE__ << "]\033[0m"; \ th__out << __FILE__ << red << ":" << __LINE__ << "]" << clear; \
if (!th__msg.str().empty()) \ if (!th__msg.str().empty()) \
th__out << "\n" << Dune::Stuff::Common::Colors::red << "=>\033[0m " << th__msg.str(); \ th__out << "\n" << red << "=>" << clear << " " << th__msg.str(); \
th__ex.message(th__out.str()); \ th__ex.message(th__out.str()); \
throw th__ex; \ throw th__ex; \
} while (0) } while (0)
// DUNE_THROW_COLORFULLY // DUNE_THROW_COLORFULLY
#ifdef DUNE_THROW
#undef DUNE_THROW
#define DUNE_THROW DUNE_THROW_COLORFULLY
#endif // DUNE_THROW
namespace Dune { namespace Dune {
namespace Stuff { namespace Stuff {
namespace Exceptions { namespace Exceptions {
......
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