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

Remove places where exceptions are unconditionally swallowed. #3258

Closed
WardBrian opened this issue Jan 23, 2024 · 0 comments · Fixed by #3259
Closed

Remove places where exceptions are unconditionally swallowed. #3258

WardBrian opened this issue Jan 23, 2024 · 0 comments · Fixed by #3259

Comments

@WardBrian
Copy link
Member

Summary:

There are a few places where we catch std::exception and do not end up re-throwing it. This prevents features like stan-dev/stanc3#1393 (an exit() function in the language), and leads to some unexpected behavior.

For example, if an indexing exception occurs during initialization, the program halts. If it occurs during sampling, it's all good. Run this program a few times to get a sense of this:

parameters {
  real mu;
}
model {
  mu ~ normal(0, 1);
  
  if (mu < 0) {
    array[1] int sigma;
    print(sigma[2]);
  }
}

Description:

I believe I have found the relevant places that need to change and highlighted them here: https://gist.github.com/WardBrian/a21b6e650606e562ca1466eedaa3eb47

When a similar change was made in #2307, the choice was to not catch anything that isn't a std::domain_error. This is what reject() throws in the language, and a lot of our math functions as well, and generally seems like a good choice for "recoverable".

Current Version:

v2.34

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant