Many Boost.Filesystem functions and methods (and the pattern also exists in Boost.Asio) will throw a boost::system::error_code in case of error, and sometimes it is not as obvious as you might expect, case in point:
In other words, the function returns true if it correctly assessed that the file exists, false if it correctly assessed that the file doesn’t exist and will throw an exception if it cannot.
Two catches here:
- boost::system::error_code doesn’t inherit from std::exception, therefore you need a specific catch
- It is easy to forget that this function can throw.
In quasardb, when we use that kind of API we prefer to use the version that takes the error code as a parameter:
// file exists, do something
// eventually test for ec depending on the context
The problem with passing an error code as a reference is that it is not immediate that the value is updated by the function.
This is why in our own code we prefer a more "modern" approach:
bool result =false;
std::tie(result, ec)= qdb::some_function();