std::filesystem::filesystem_error::what
From cppreference.com
< cpp | filesystem | filesystem error
const char* what() const noexcept override; |
(since C++17) | |
Returns an explanatory byte string. This explanatory string contains the explanatory string passed at the time of construction. Implementations are encouraged to include the pathnames of path1() and path2() in native format and the std::system_error::what() string inside the returned string as well.
Parameters
(none)
Example
Run this code
#include <cstdio> #include <filesystem> #include <iostream> int main() { try { std::filesystem::rename("/dev", "/null"); } catch(std::filesystem::filesystem_error const& ex) { std::cout << "1) std::filesystem::rename():\n" << "what(): " << ex.what() << '\n' << "path1(): " << ex.path1() << '\n' << "path2(): " << ex.path2() << '\n'; } try { std::filesystem::create_directory("/bool"); } catch(std::filesystem::filesystem_error const& ex) { std::cout << "2) std::filesystem::create_directory():\n" << "what(): " << ex.what() << '\n' << "path1(): " << ex.path1() << '\n' << "path2(): " << ex.path2() << '\n'; } }
Possible output:
1) std::filesystem::rename(): what(): filesystem error: in rename: Permission denied [/dev] [/null] path1(): "/dev" path2(): "/null" 2) std::filesystem::create_directory(): what(): filesystem error: in create_directory: Permission denied [/bool] path1(): "/bool" path2(): ""