std::filesystem::filesystem_error::path1, std::filesystem::filesystem_error::path2
来自cppreference.com
< cpp | filesystem | filesystem error
const std::filesystem::path& path1() const noexcept; |
(C++17 起) | |
const std::filesystem::path& path2() const noexcept; |
(C++17 起) | |
返回存储于异常对象中的路径。
参数
(无)
返回值
到构造函数所存储的 path
参数的副本的引用。
示例
运行此代码
#include <cstdio> #include <filesystem> #include <iostream> int main() { const std::filesystem::path old_p{std::tmpnam(nullptr)}, new_p{std::tmpnam(nullptr)}; try { std::filesystem::rename(old_p, new_p); // 因为 old_p 不存在而抛出 } catch(std::filesystem::filesystem_error const& ex) { std::cout << "what(): " << ex.what() << '\n' << "path1(): " << ex.path1() << '\n' << "path2(): " << ex.path2() << '\n'; } }
可能的输出:
what(): filesystem error: cannot rename: No such file or directory [/tmp/fileIzzRLB] [/tmp/fileiUDWlV] path1(): "/tmp/fileIzzRLB" path2(): "/tmp/fileiUDWlV"