create_buffer_from_file: throw file_not_found instead of open_file_error when ENOENT

This commit is contained in:
Maxime Coste 2011-09-02 18:01:20 +00:00
parent 955744e5d0
commit 11d82b11b3
2 changed files with 11 additions and 0 deletions

View File

@ -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];

View File

@ -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)