diff --git a/src/ReadIterations.cpp b/src/ReadIterations.cpp index b677d97535..371f4610bd 100644 --- a/src/ReadIterations.cpp +++ b/src/ReadIterations.cpp @@ -23,6 +23,8 @@ #include "openPMD/Series.hpp" +#include + namespace openPMD { @@ -108,7 +110,23 @@ SeriesIterator &SeriesIterator::operator++() // since we are in group-based iteration layout, it does not // matter which iteration we begin a step upon AdvanceStatus status{}; - status = currentIteration.beginStep(/* reread = */ true); + try + { + status = currentIteration.beginStep(/* reread = */ true); + } + catch (error::ReadError const &err) + { + std::cerr << "[SeriesIterator] Cannot read iteration due to error " + "below, will skip it.\n" + << err.what() << std::endl; + // Need to close the current step manually because there is no + // iteration to close + Parameter param; + param.mode = AdvanceMode::ENDSTEP; + series.IOHandler()->enqueue(IOTask(&series, std::move(param))); + series.IOHandler()->flush({FlushLevel::UserFlush}); + return operator++(); + } if (status == AdvanceStatus::OVER) { *this = end(); @@ -144,7 +162,17 @@ SeriesIterator &SeriesIterator::operator++() case IE::fileBased: { auto &iteration = series.iterations[m_currentIteration]; AdvanceStatus status{}; - status = iteration.beginStep(/* reread = */ true); + try + { + status = iteration.beginStep(/* reread = */ true); + } + catch (error::ReadError const &err) + { + std::cerr << "[SeriesIterator] Cannot read iteration due to error " + "below, will skip it.\n" + << err.what() << std::endl; + return operator++(); + } if (status == AdvanceStatus::OVER) { *this = end();