diff --git a/include/rfl/io/save_bytes.hpp b/include/rfl/io/save_bytes.hpp index 0c5fc2081..868a0cda1 100644 --- a/include/rfl/io/save_bytes.hpp +++ b/include/rfl/io/save_bytes.hpp @@ -15,6 +15,9 @@ Result save_bytes(const std::string& _fname, const T& _obj, const WriteFunction& _write) { try { std::ofstream output(_fname, std::ios::out | std::ios::binary); + if (!output.is_open()) { + return error("Unable to open file '" + _fname + "' for writing."); + } _write(_obj, output); output.close(); } catch (std::exception& e) { diff --git a/include/rfl/io/save_string.hpp b/include/rfl/io/save_string.hpp index f7c7e6e31..17ee1433d 100644 --- a/include/rfl/io/save_string.hpp +++ b/include/rfl/io/save_string.hpp @@ -15,6 +15,9 @@ Result save_string(const std::string& _fname, const T& _obj, try { std::ofstream outfile; outfile.open(_fname); + if (!outfile.is_open()) { + return error("Unable to open file '" + _fname + "' for writing."); + } _write(_obj, outfile); outfile.close(); } catch (std::exception& e) {