From 11d82b11b31249461a4a5a6ad32b5a3841083ce9 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 2 Sep 2011 18:01:20 +0000 Subject: [PATCH] create_buffer_from_file: throw file_not_found instead of open_file_error when ENOENT --- src/file.cc | 5 +++++ src/file.hh | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/file.cc b/src/file.cc index 17150248..f6fc1f24 100644 --- a/src/file.cc +++ b/src/file.cc @@ -14,7 +14,12 @@ Buffer* create_buffer_from_file(const std::string& filename) { int fd = open(filename.c_str(), O_RDONLY); if (fd == -1) + { + if (errno == ENOENT) + throw file_not_found(strerror(errno)); + throw open_file_error(strerror(errno)); + } std::string content; char buf[256]; diff --git a/src/file.hh b/src/file.hh index 0a4c9d06..fa91e347 100644 --- a/src/file.hh +++ b/src/file.hh @@ -13,6 +13,12 @@ struct open_file_error : public std::runtime_error : std::runtime_error(what) {} }; +struct file_not_found : public open_file_error +{ + file_not_found(const std::string& what) + : open_file_error(what) {} +}; + struct write_file_error : public std::runtime_error { write_file_error(const std::string& what)