Skip to content

Commit

Permalink
Merge pull request #3834 from AllisonJohn/casadi_solver_exceptions
Browse files Browse the repository at this point in the history
Added exceptions for when CasOCSolver solve() fails in MocoCasADiSolver
  • Loading branch information
nickbianco authored Jul 3, 2024
2 parents 7e7f649 + fab21fb commit accddd7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ pointer to avoid crashes in scripting due to invalid pointer ownership (#3781).
- Fixed bug in `Logger::cout`, now it works at any logger level. (#3826)
- Fixed bugs in `MocoCasOCProblem` and `CasOC::Problem` with incorrect string formatting. (#3828)
- Fixed `MocoOrientationTrackingGoal::initializeOnModelImpl` to check for missing kinematic states, but allow other missing columns. (#3830)
- Improved exception handling for internal errors in `MocoCasADiSolver`. Problems will now abort and print a descriptive error message (rather than fail due to an empty trajectory). (#3834)



v4.5
Expand Down
10 changes: 9 additions & 1 deletion OpenSim/Moco/MocoCasADiSolver/MocoCasADiSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,16 @@ MocoSolution MocoCasADiSolver::solveImpl() const {
CasOC::Solution casSolution;
try {
casSolution = casSolver->solve(casGuess);
} catch(const Exception& ex) {
OPENSIM_THROW_FRMOBJ(Exception,
fmt::format("MocoCasADiSolver failed internally with message: {}",
ex.getMessage()));
} catch(const casadi::CasadiException& ex) {
OPENSIM_THROW_FRMOBJ(Exception,
fmt::format("MocoCasADiSolver failed internally with message: {}",
ex.what()));
} catch (...) {
OpenSim::Logger::setLevel(origLoggerLevel);
OPENSIM_THROW_FRMOBJ(Exception, "MocoCasADiSolver failed internally.");
}
OpenSim::Logger::setLevel(origLoggerLevel);

Expand Down

0 comments on commit accddd7

Please sign in to comment.