Skip to content

Commit

Permalink
[RF] Throw exception if element in RooAbsCollection can't be replaced
Browse files Browse the repository at this point in the history
This would leave the collection in an undesired state, so it's not good
to continue at that point.
  • Loading branch information
guitargeek committed Apr 19, 2024
1 parent 14d7668 commit 6d47b91
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions roofit/roofitcore/src/RooAbsCollection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?
Expand Down

0 comments on commit 6d47b91

Please sign in to comment.