Browse Source

Cleaner error handling in dds::open

default_compile_flags
vector-of-bool 3 years ago
parent
commit
1bbd32aa05
1 changed files with 2 additions and 7 deletions
  1. +2
    -7
      src/dds/util/fs.cpp

+ 2
- 7
src/dds/util/fs.cpp View File

using namespace dds; using namespace dds;


std::fstream dds::open(const fs::path& filepath, std::ios::openmode mode, std::error_code& ec) { std::fstream dds::open(const fs::path& filepath, std::ios::openmode mode, std::error_code& ec) {
std::fstream ret;
auto mask = ret.exceptions() | std::ios::badbit;
ret.exceptions(mask);

try {
ret.open(filepath.string(), mode);
} catch (const std::ios::failure&) {
std::fstream ret{filepath, mode};
if (!ret) {
ec = std::error_code(errno, std::system_category()); ec = std::error_code(errno, std::system_category());
} }
return ret; return ret;

Loading…
Cancel
Save