create_buffer_from_file: throw file_not_found instead of open_file_error when ENOENT
This commit is contained in:
parent
955744e5d0
commit
11d82b11b3
|
@ -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];
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user