From 6d8c0d38e52d6e7cf476354c6191c54d8333e5ab Mon Sep 17 00:00:00 2001 From: Timo Koch <timo.koch@iws.uni-stuttgart.de> Date: Wed, 15 May 2019 16:27:12 +0200 Subject: [PATCH] [io] Improve error handling when adding wrong data vectors --- dumux/io/gnuplotinterface.hh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/dumux/io/gnuplotinterface.hh b/dumux/io/gnuplotinterface.hh index 55fa13e5e7..22950c5edd 100644 --- a/dumux/io/gnuplotinterface.hh +++ b/dumux/io/gnuplotinterface.hh @@ -42,7 +42,7 @@ #include <string> #include <vector> -#include <dune/common/deprecated.hh> +#include <dune/common/exceptions.hh> #include <dune/common/stdstreams.hh> namespace Dumux { @@ -244,7 +244,15 @@ public: const std::string& fileName, const std::string& options = "with lines") { - assert(x.size() == y.size()); + if (x.empty() || y.empty()) + DUNE_THROW(Dune::InvalidStateException, "Data vectors have to contain data!"); + + if (x.size() > y.size()) + DUNE_THROW(Dune::InvalidStateException, "Non-matching data field sizes!"); + + if (x.size() != y.size()) + std::cout << "GnuplotInterface warning: Added data fields of different size! " + << "Only plotting the first " << x.size() << " elements.\n"; // write data to file std::ofstream file; @@ -435,5 +443,5 @@ private: std::string plotOptions_; std::string gnuplotPath_; }; -} // end of namespace +} // end namespace Dumux #endif // DUMUX_GNUPLOT_INTERFACE_HH -- GitLab