From 6d47b919e62fa60453808745f07b3d1e9feded77 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Fri, 19 Apr 2024 01:21:12 +0200 Subject: [PATCH] [RF] Throw exception if element in `RooAbsCollection` can't be replaced This would leave the collection in an undesired state, so it's not good to continue at that point. --- roofit/roofitcore/src/RooAbsCollection.cxx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/roofit/roofitcore/src/RooAbsCollection.cxx b/roofit/roofitcore/src/RooAbsCollection.cxx index b906d628a47d6..edf331341a6d4 100644 --- a/roofit/roofitcore/src/RooAbsCollection.cxx +++ b/roofit/roofitcore/src/RooAbsCollection.cxx @@ -536,8 +536,11 @@ bool RooAbsCollection::replace(const RooAbsCollection &other) { // check that this isn't a copy of a list if(_ownCont) { - coutE(ObjectHandling) << "RooAbsCollection: cannot replace variables in a copied list" << std::endl; - return false; + std::stringstream errMsg; + errMsg << "RooAbsCollection: cannot replace variables in a copied list"; + coutE(ObjectHandling) << errMsg.str() << std::endl; + // better than returning "false" and leaving the collection in a broken state: + throw std::invalid_argument(errMsg.str()); } // loop over elements in the other list @@ -561,8 +564,11 @@ bool RooAbsCollection::replace(const RooAbsArg& var1, const RooAbsArg& var2) { // check that this isn't a copy of a list if(_ownCont) { - coutE(ObjectHandling) << "RooAbsCollection: cannot replace variables in a copied list" << std::endl; - return false; + std::stringstream errMsg; + errMsg << "RooAbsCollection: cannot replace variables in a copied list"; + coutE(ObjectHandling) << errMsg.str() << std::endl; + // better than returning "false" and leaving the collection in a broken state: + throw std::invalid_argument(errMsg.str()); } // is var1 already in this list?