From 6836a1bd4090c0d6bfb8bfa555f13a2f0a7d2ee7 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Fri, 30 Oct 2015 18:10:48 +0100 Subject: [PATCH] Better exceptions --- data/Data.h | 3 +++ tempfile/TempFile.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/data/Data.h b/data/Data.h index 37a6375a..ff3916a1 100644 --- a/data/Data.h +++ b/data/Data.h @@ -120,6 +120,9 @@ inline Data &Data::FillWithZeroes() { inline void Data::StoreToFile(const boost::filesystem::path &filepath) const { std::ofstream file(filepath.c_str(), std::ios::binary | std::ios::trunc); + if (!file.good()) { + throw std::runtime_error("Could not open file for writing"); + } StoreToStream(file); } diff --git a/tempfile/TempFile.cpp b/tempfile/TempFile.cpp index 5307fc1d..14db0081 100644 --- a/tempfile/TempFile.cpp +++ b/tempfile/TempFile.cpp @@ -11,6 +11,9 @@ TempFile::TempFile(const bf::path &path, bool create) : _path(path) { if (create) { ofstream file(_path.c_str()); + if (!file.good()) { + throw std::runtime_error("Could not create tempfile"); + } } }