Basing from https://en.cppreference.com/w/cpp/filesystem/current_path (to get current working directory) fs::current_path should pass any errors to the error_code structure and not throw any errors via current_path function but... does that actually work?
Variant with error_code is not marked as noexcept so it may throw. Does that apply only to bad_alloc or...?
#`fs::current_path()` and `std::error_code` - throw or noexcept?
8 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
Well actually it doesnt even throw when there is no memory left
Exceptions
Any overload not marked noexcept may throw std::bad_alloc if memory allocation fails.
1) Throws std::filesystem::filesystem_error on underlying OS API errors, constructed with the OS error code as the error code argument.
2) Sets a std::error_code& parameter to the OS API error code if an OS API call fails, and executes ec.clear() if no errors occur.
3) Throws std::filesystem::filesystem_error on underlying OS API errors, constructed with p as the first path argument and the OS error code as the error code argument.
4) Sets a std::error_code& parameter to the OS API error code if an OS API call fails, and executes ec.clear() if no errors occur.
I see but that doesnt answer my question. None of these functions with error_code are marked noexcept. In their source code they also dont throw yet they arent marked noexcept. So whats going on?
std::bad_alloc is the reason
either exceptions gets thrown, or error_code saves the error without throwing anything