Namespaces
Variants

std::filesystem::filesystem_error:: filesystem_error

From cppreference.net
filesystem_error ( const std:: string & what_arg,
std:: error_code ec ) ;
(1) (C++17 起)
filesystem_error ( const std:: string & what_arg,

const std:: filesystem :: path & p1,

std:: error_code ec ) ;
(2) (C++17 起)
filesystem_error ( const std:: string & what_arg,

const std:: filesystem :: path & p1,
const std:: filesystem :: path & p2,

std:: error_code ec ) ;
(3) (C++17 起)
filesystem_error ( const filesystem_error & other ) noexcept ;
(4) (C++17 起)

构造一个新的 filesystem_error 对象。

1-3) 将错误码设置为 ec ,并可选地将导致该操作所涉及的路径设置为 p1 p2 。构造后 what() 返回的字符串包含 what_arg (假设其不包含嵌入的空字符)。如果未提供任一或两个 path 参数,则使用空 path 作为替代。
4) 复制构造函数。使用 other 的内容初始化当前对象内容。若 * this other 均具有动态类型 std::filesystem_error::filesystem_error ,则满足 std:: strcmp ( what ( ) , other. what ( ) ) == 0

参数

what_arg - 说明性字符串
ec - 特定操作系统相关错误的错误代码
p1, p2 - 引发系统错误的操作中涉及的路径
other - 要复制的另一个 filesystem_error 对象

注释

由于不允许在复制 std::filesystem::filesystem_error 时抛出异常,解释性字符串通常存储在单独分配的引用计数存储中。这也是为什么不存在接收 std::string&& 参数的构造函数:因为无论如何都需要复制内容。

典型实现还会在引用计数存储中存储由 path1() path2() 引用的 path 对象。

示例