mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 00:38:08 +08:00
fix: Improve error handling of ifstream a bit
Set the exceptions mask so that exceptions are thrown when an I/O error occurs. Also throw the same exception type when the opening fails.
This commit is contained in:
@@ -1031,5 +1031,5 @@ BOOST_AUTO_TEST_CASE(test_parse_function_compiles)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_parse_nonexistent_file)
|
BOOST_AUTO_TEST_CASE(test_parse_nonexistent_file)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_THROW(toml::parse("nonexistent.toml"), std::runtime_error);
|
BOOST_CHECK_THROW(toml::parse("nonexistent.toml"), std::ios_base::failure);
|
||||||
}
|
}
|
||||||
|
@@ -2488,8 +2488,9 @@ basic_value<Comment, Table, Array> parse(std::string fname)
|
|||||||
std::ifstream ifs(fname, std::ios_base::binary);
|
std::ifstream ifs(fname, std::ios_base::binary);
|
||||||
if(!ifs.good())
|
if(!ifs.good())
|
||||||
{
|
{
|
||||||
throw std::runtime_error("toml::parse: file open error -> " + fname);
|
throw std::ios_base::failure("toml::parse: Error opening file \"" + fname + "\"");
|
||||||
}
|
}
|
||||||
|
ifs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||||
return parse<Comment, Table, Array>(ifs, std::move(fname));
|
return parse<Comment, Table, Array>(ifs, std::move(fname));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user