Add better error reporting

release/4.3a0
Frank Dellaert 2019-06-15 11:11:11 -04:00
parent 28235955d0
commit ba91bd53fd
3 changed files with 35 additions and 19 deletions

View File

@ -1870,7 +1870,6 @@ class NonlinearFactorGraph {
// FactorGraph // FactorGraph
void print(string s) const; void print(string s) const;
void printErrors(const gtsam::Values& values);
bool equals(const gtsam::NonlinearFactorGraph& fg, double tol) const; bool equals(const gtsam::NonlinearFactorGraph& fg, double tol) const;
size_t size() const; size_t size() const;
bool empty() const; bool empty() const;
@ -1887,6 +1886,7 @@ class NonlinearFactorGraph {
gtsam::KeyVector keyVector() const; gtsam::KeyVector keyVector() const;
// NonlinearFactorGraph // NonlinearFactorGraph
void printErrors(const gtsam::Values& values) const;
double error(const gtsam::Values& values) const; double error(const gtsam::Values& values) const;
double probPrime(const gtsam::Values& values) const; double probPrime(const gtsam::Values& values) const;
gtsam::Ordering orderingCOLAMD() const; gtsam::Ordering orderingCOLAMD() const;

View File

@ -342,17 +342,21 @@ vector<Class> Class::expandTemplate(Str templateArg,
/* ************************************************************************* */ /* ************************************************************************* */
void Class::addMethod(bool verbose, bool is_const, Str methodName, void Class::addMethod(bool verbose, bool is_const, Str methodName,
const ArgumentList& argumentList, const ReturnValue& returnValue, const ArgumentList& argumentList,
const Template& tmplate) { const ReturnValue& returnValue, const Template& tmplate) {
// Check if templated // Check if templated
if (tmplate.valid()) { if (tmplate.valid()) {
try {
templateMethods_[methodName].addOverload(methodName, argumentList, templateMethods_[methodName].addOverload(methodName, argumentList,
returnValue, is_const, returnValue, is_const,
tmplate.argName(), verbose); tmplate.argName(), verbose);
} catch (const std::runtime_error& e) {
throw std::runtime_error("Class::addMethod: error adding " + name_ +
"::" + methodName + "\n" + e.what());
}
// Create method to expand // Create method to expand
// For all values of the template argument, create a new method // For all values of the template argument, create a new method
for (const Qualified& instName : tmplate.argValues()) { for (const Qualified& instName : tmplate.argValues()) {
const TemplateSubstitution ts(tmplate.argName(), instName, *this); const TemplateSubstitution ts(tmplate.argName(), instName, *this);
// substitute template in arguments // substitute template in arguments
ArgumentList expandedArgs = argumentList.expandTemplate(ts); ArgumentList expandedArgs = argumentList.expandTemplate(ts);
@ -361,15 +365,27 @@ void Class::addMethod(bool verbose, bool is_const, Str methodName,
// Now stick in new overload stack with expandedMethodName key // Now stick in new overload stack with expandedMethodName key
// but note we use the same, unexpanded methodName in overload // but note we use the same, unexpanded methodName in overload
string expandedMethodName = methodName + instName.name(); string expandedMethodName = methodName + instName.name();
try {
methods_[expandedMethodName].addOverload(methodName, expandedArgs, methods_[expandedMethodName].addOverload(methodName, expandedArgs,
expandedRetVal, is_const, instName, verbose); expandedRetVal, is_const,
instName, verbose);
} catch (const std::runtime_error& e) {
throw std::runtime_error("Class::addMethod: error adding " + name_ +
"::" + expandedMethodName + "\n" + e.what());
}
} }
} else { } else {
try {
// just add overload // just add overload
methods_[methodName].addOverload(methodName, argumentList, returnValue, methods_[methodName].addOverload(methodName, argumentList, returnValue,
is_const, boost::none, verbose); is_const, boost::none, verbose);
nontemplateMethods_[methodName].addOverload(methodName, argumentList, returnValue, nontemplateMethods_[methodName].addOverload(methodName, argumentList,
is_const, boost::none, verbose); returnValue, is_const,
boost::none, verbose);
} catch (const std::runtime_error& e) {
throw std::runtime_error("Class::addMethod: error adding " + name_ +
"::" + methodName + "\n" + e.what());
}
} }
} }

View File

@ -38,12 +38,12 @@ bool Method::addOverload(Str name, const ArgumentList& args,
is_const_ = is_const; is_const_ = is_const;
else if (is_const && !is_const_) else if (is_const && !is_const_)
throw std::runtime_error( throw std::runtime_error(
"Method::addOverload now designated as const whereas before it was " "Method::addOverload: " + name +
"not"); " now designated as const whereas before it was not");
else if (!is_const && is_const_) else if (!is_const && is_const_)
throw std::runtime_error( throw std::runtime_error(
"Method::addOverload now designated as non-const whereas before it " "Method::addOverload: " + name +
"was"); " now designated as non-const whereas before it was");
return first; return first;
} }