Answer the question
In order to leave comments, you need to log in
How to return an error in std::filesystem?
For example, this is how I do it using runtime_error:
#include <exception>
#include <filesystem>
std::exception &foo(){
try {
if(!std::filesystem::is_directory(std::filesystem::path("sdfsdf"))){
throw std::runtime_error("Error14");
}
}
catch (std::exception &e) {
return e;
}
}
int main(){
foo().what();
// далее обработка принятого сообщения
}
std::filesystem::filesystem_error
Answer the question
In order to leave comments, you need to log in
For example, there is such an addendum at https://en.cppreference.com/w/cpp/filesystem/files...
In order to ensure that copy functions of filesystem_error are noexcept, typical implementations store an object holding the return value of what() and two std::filesystem::path objects referenced by path1() and path2() respectively in a separately-allocated reference-counted storage.
Currently the MS STL implementation is non-conforming: the objects mentioned above are stored directly in the filesystem object, which makes the copy functions not noexcept.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question