From 09fd4df0e2a936cd0f8d445b8f377bb14ad5694c Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Thu, 29 Jun 2017 00:25:39 -0700 Subject: [PATCH] change json::Source::load_file to produce a more descriptive exception message --- src/json/source.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/json/source.cpp b/src/json/source.cpp index 833bee1..93e7eba 100644 --- a/src/json/source.cpp +++ b/src/json/source.cpp @@ -102,8 +102,12 @@ Source Source::load_file(const util::filesystem::path &file_path) { // TODO: add code to use mmap std::ifstream is; - is.exceptions(std::ios::badbit | std::ios::failbit); + is.exceptions(std::ios::badbit); is.open(file_path); + if(!is) + throw util::filesystem::filesystem_error( + "open failed", file_path, std::make_error_code(std::io_errc::stream)); + is.exceptions(std::ios::badbit | std::ios::failbit); std::vector buffer; while(is.peek() != std::char_traits::eof()) { -- 2.30.2