std::filesy...error::path2(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

Okay so this is the std::filesy...error::path2(3) page from the C++ Standard Libary manual, and it covers both path1 and path2 like the iconic duo they are. Bestie, it’s giving β€œtwo path functions, one manpage,” and we’re keeping every detail, no cap.


πŸ’… NAME πŸ’…

  • std::filesystem::filesystem_error::path1,std::filesystem::filesystem_error::path2 β€” yes, that’s literally the name, comma and all, no space after it. The original lists it twice, so we’re honoring the double-listing energy. πŸ’–

✨ Synopsis ✨

const std::filesystem::path& path1() const noexcept;  (since C++17)
const std::filesystem::path& path2() const noexcept;  (since C++17)

Both are noexcept and both show up since C++17, periodt. The vibe check says: they return the paths that were stored in the exception object. πŸ¦‹

🌸 Parameters 🌸

(none) β€” literally zero parameters, not a single one, bestie. 🫢

πŸŽ€ Return value πŸŽ€

References to the copy of the path parameters stored by the constructor. Lowkey that’s the whole return-value vibe: references to the copies the constructor stored, ngl. ✨

πŸ¦‹ Example πŸ¦‹

// Run this code β€” yes bestie, run it, fr fr:

        #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); // throws since old_p
       does not exist
            }
            catch(std::filesystem::filesystem_error const& ex) {
                std::cout
                    << "what():  " << ex.what() << '\n'
                    << "path1(): " << ex.path1() << '\n'
                    << "path2(): " << ex.path2() << '\n';
            }
        }

πŸ’œ Possible output πŸ’œ

Possible output, and it might look exactly like this β€” iykyk:

        what():  filesystem error: cannot rename: No such file or directory
       [/tmp/fileIzzRLB] [/tmp/fileiUDWlV]
        path1(): "/tmp/fileIzzRLB"
        path2(): "/tmp/fileiUDWlV"

Source/version/date check: http://cppreference.com, 2024.06.10, page std::filesy...error::path2(3) β€” that’s the cute little footer folded into a sign-off, mwah πŸ’‹πŸ’–

πŸ“¦ where this page comes from