Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put error context into the exception message instead of dumping to std::cout in DetectorImp::getRefChild() #1106

Merged
merged 2 commits into from
May 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions DDCore/src/DetectorImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,9 +631,9 @@ vector<DetElement> DetectorImp::detectors(const string& type1,
}

Handle<NamedObject> DetectorImp::getRefChild(const HandleMap& e, const string& name, bool do_throw) const {
HandleMap::const_iterator i = e.find(name);
if (i != e.end()) {
return (*i).second;
HandleMap::const_iterator it = e.find(name);
if (it != e.end()) {
return it->second;
}
if (do_throw) {
union ptr {
Expand All @@ -642,15 +642,20 @@ Handle<NamedObject> DetectorImp::getRefChild(const HandleMap& e, const string& n
const void* other;
ptr(const void* p) { other = p; }
};
int cnt = 0;
std::string nam = "";
ptr m(&e), ref(this);
if ( ref.c > m.c && m.c < ref.c+sizeof(*this) ) nam = m.omap->name;
cout << "GetRefChild: Failed to find child with name: '" << name
<< "'. Map " << nam << " contains " << e.size() << " elements." << endl;
for(i=e.begin(); i!=e.end(); ++i)
cout << " " << cnt << " " << (*i).first << endl;
throw runtime_error(nam+": Cannot find a child with the reference name:" + name);
std::stringstream err;
err << "getRefChild: Failed to find child with name: " << name
<< " Map " << nam << " contains " << e.size() << " elements: {";
for (it = e.begin(); it != e.end(); ++it) {
if (it != e.begin()) {
err << ", ";
}
err << it->first;
}
err << "}";
throw runtime_error(err.str());
}
return 0;
}
Expand Down