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

CVODES exceptions converted to domain_error #3013

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 4 additions & 12 deletions stan/math/prim/err/check_flag_sundials.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,19 @@ inline std::array<std::string, 2> cvodes_flag_msg(int flag) {
}

/**
* Throws a std::runtime_error exception when a Sundial function fails
* Throws a std::domain_error exception when a Sundial function fails
* (i.e. returns a negative flag)
*
* @param flag Error flag
* @param func_name Name of the function that returned the flag
* @throw <code>std::runtime_error</code> if the flag is negative
* @throw <code>std::domain_error</code> if the flag is negative
*/
inline void cvodes_check(int flag, const char* func_name) {
if (flag < 0) {
std::ostringstream ss;
ss << func_name << " failed with error flag " << flag << ": \n"
<< cvodes_flag_msg(flag).at(1) << ".";
if (flag == -1 || flag == -4) {
throw std::domain_error(ss.str());
} else {
throw std::runtime_error(ss.str());
}
throw std::domain_error(ss.str());
}
}

Expand Down Expand Up @@ -368,11 +364,7 @@ inline void idas_check(int flag, const char* func_name) {
std::ostringstream ss;
ss << func_name << " failed with error flag " << flag << ": \n"
<< idas_flag_msg(flag).at(1);
if (flag == -1 || flag == -4) {
throw std::domain_error(ss.str());
} else {
throw std::runtime_error(ss.str());
}
throw std::domain_error(ss.str());
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/unit/math/rev/functor/index_3_dae_typed_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ using dae_test_types = boost::mp11::mp_product<

TYPED_TEST_SUITE_P(index_3_dae_test);
TYPED_TEST_P(index_3_dae_test, solver_failure) {
EXPECT_THROW_MSG(this->apply_solver(), std::runtime_error,
EXPECT_THROW_MSG(this->apply_solver(), std::domain_error,
"Error test failures occurred too many times");
this->ts = {0.0001};
EXPECT_THROW_MSG(this->apply_solver_tol(), std::runtime_error,
EXPECT_THROW_MSG(this->apply_solver_tol(), std::domain_error,
"Error test failures occurred too many times");
}

Expand Down
Loading