opensim-org / opensim-core

SimTK OpenSim C++ libraries and command-line applications, and Java/Python wrapping.
https://opensim.stanford.edu
Apache License 2.0
759 stars 308 forks source link

Added exceptions for when CasOCSolver solve() fails in MocoCasADiSolver #3834

Closed AllisonJohn closed 3 days ago

AllisonJohn commented 4 days ago

Fixes issue #3730

Brief summary of changes

Instead of continuing on, MocoCasADiSolver will throw exceptions when the solver doesn't fails so that the next lines don't cause more errors.

Testing I've completed

Tested putting opensim, casadi, and std errors in the try section to see the error messages when running the sliding mass problem. Without the added errors it works normally.

Looking for feedback on...

CHANGELOG.md (choose one)


This change is Reviewable

AllisonJohn commented 4 days ago

Here is what happens when adding each of these lines to the catch:

OPENSIM_THROW(Exception, "test opensim exception"); -> image

casadi_error("test casadi exception"); -> image "libc++abi: terminating due to uncaught exception of type OpenSim::Exception: MocoCasADiSolver failed internally with message: /Users/allisonjohn/Documents/opensim-core/OpenSim/Moco/MocoCasADiSolver/MocoCasADiSolver.cpp:388: test casadi exception In Object '' of type MocoCasADiSolver. Thrown at MocoCasADiSolver.cpp:396 in solveImpl()."

throw std::invalid_argument("test exception"); -> image