30 Input/output library [input.output]

30.10 File systems [filesystems]

30.10.28 Class filesystem_­error [fs.class.filesystem_error]

namespace std::filesystem {
  class filesystem_error : public system_error {
  public:
    filesystem_error(const string& what_arg, error_code ec);
    filesystem_error(const string& what_arg,
                     const path& p1, error_code ec);
    filesystem_error(const string& what_arg,
                     const path& p1, const path& p2, error_code ec);

    const path& path1() const noexcept;
    const path& path2() const noexcept;
    const char* what() const noexcept override;
  };
}

The class filesystem_­error defines the type of objects thrown as exceptions to report file system errors from functions described in this subclause.

30.10.28.1 filesystem_­error members [filesystem_error.members]

Constructors are provided that store zero, one, or two paths associated with an error.

filesystem_error(const string& what_arg, error_code ec);

Postconditions: The postconditions of this function are indicated in Table 119.

Table 119filesystem_­error(const string&, error_­code) effects
ExpressionValue
runtime_­error​::​what() what_­arg.c_­str()
code() ec
path1().empty() true
path2().empty() true

filesystem_error(const string& what_arg, const path& p1, error_code ec);

Postconditions: The postconditions of this function are indicated in Table 120.

Table 120filesystem_­error(const string&, const path&, error_­code) effects
ExpressionValue
runtime_­error​::​what() what_­arg.c_­str()
code() ec
path1() Reference to stored copy of p1
path2().empty() true

filesystem_error(const string& what_arg, const path& p1, const path& p2, error_code ec);

Postconditions: The postconditions of this function are indicated in Table 121.

Table 121filesystem_­error(const string&, const path&, const path&, error_­code) effects
ExpressionValue
runtime_­error​::​what() what_­arg.c_­str()
code() ec
path1() Reference to stored copy of p1
path2() Reference to stored copy of p2

const path& path1() const noexcept;

Returns: A reference to the copy of p1 stored by the constructor, or, if none, an empty path.

const path& path2() const noexcept;

Returns: A reference to the copy of p2 stored by the constructor, or, if none, an empty path.

const char* what() const noexcept override;

Returns: A string containing runtime_­error​::​what(). The exact format is unspecified. Implementations are encouraged but not required to include path1.native_­string() if not empty, path2.native_­string() if not empty, and system_­error​::​what() strings in the returned string.