Skip to content

Commit

Permalink
Merge pull request #37591 from Dr15Jones/betterExceptionDelayedReader
Browse files Browse the repository at this point in the history
Better exception messages from ROOT delayed reading
  • Loading branch information
cmsbuild authored Apr 18, 2022
2 parents f6922d8 + 0386e85 commit 9bac750
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 12 additions & 2 deletions FWCore/Integration/test/DelayedReaderThrowingSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ namespace edm {
ThrowingDelayedReader(
signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* preEventReadSource,
signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* postEventReadSource)
: preEventReadFromSourceSignal_(preEventReadSource), postEventReadFromSourceSignal_(postEventReadSource) {}
: preEventReadFromSourceSignal_(preEventReadSource),
postEventReadFromSourceSignal_(postEventReadSource),
e_(std::make_exception_ptr(cms::Exception("TEST"))) {}

signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* preEventReadFromSourceSignal()
const final {
Expand All @@ -35,7 +37,14 @@ namespace edm {

private:
std::shared_ptr<WrapperBase> getProduct_(BranchID const& k, EDProductGetter const* ep) final {
throw cms::Exception("TEST");
try {
std::rethrow_exception(e_);
} catch (cms::Exception const& iE) {
//avoid adding to the context for each call
auto copyException = iE;
copyException.addContext("called ThrowingDelayedReader");
throw copyException;
}
}
void mergeReaders_(DelayedReader*) final{};
void reset_() final{};
Expand All @@ -44,6 +53,7 @@ namespace edm {
nullptr;
signalslot::Signal<void(StreamContext const&, ModuleCallingContext const&)> const* postEventReadFromSourceSignal_ =
nullptr;
std::exception_ptr e_;
};
} // namespace

Expand Down
6 changes: 6 additions & 0 deletions IOPool/Input/src/RootDelayedReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ namespace edm {
if (lastException_) {
try {
std::rethrow_exception(lastException_);
} catch (edm::Exception const& e) {
//avoid growing the context each time the exception is rethrown.
auto copy = e;
copy.addContext("Rethrowing an exception that happened on a different read request.");
throw copy;
} catch (cms::Exception& e) {
//If we do anything here to 'copy', we would lose the actual type of the exception.
e.addContext("Rethrowing an exception that happened on a different read request.");
throw;
}
Expand Down

0 comments on commit 9bac750

Please sign in to comment.