File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -272,7 +272,7 @@ std::ifstream safe_open(const std::string &fname) {
272272std::unique_ptr<std::ofstream> safe_create (const std::string &fname,
273273 int sig_figs) {
274274 auto ofs = std::make_unique<std::ofstream>(fname.c_str ());
275- ofs->exceptions (std::ofstream::badbit);
275+ ofs->exceptions (std::ofstream::badbit | std::ofstream::failbit );
276276 if (sig_figs > -1 ) {
277277 ofs->precision (sig_figs);
278278 }
Original file line number Diff line number Diff line change 1+ #include < stdexcept>
2+ #include < iostream>
3+ #include < cerrno>
4+
15#include < cmdstan/command.hpp>
26#include < stan/services/error_codes.hpp>
37
@@ -8,6 +12,11 @@ int main(int argc, const char *argv[]) {
812 return cmdstan::return_codes::OK;
913 else
1014 return cmdstan::return_codes::NOT_OK;
15+ } catch (std::system_error &e) {
16+ // system_error is thrown by std::ofstream but the
17+ // message is not always helpful, so we also print errno
18+ std::cerr << e.what () << " : " << std::strerror (errno) << std::endl;
19+ return cmdstan::return_codes::NOT_OK;
1120 } catch (const std::exception &e) {
1221 std::cerr << e.what () << std::endl;
1322 return cmdstan::return_codes::NOT_OK;
You can’t perform that action at this time.
0 commit comments