Skip to content

failed to print error code :s fail on windows due to encoding error #4436

@trim21

Description

@trim21
#include <exception>
#include <filesystem>
#include <iostream>

#include "fmt/ostream.h"
#include "fmt/std.h"

namespace fs = std::filesystem;

int main() {
    const fs::path from{"/none1/a"}, to{"/none2/b"};

    try {
        fs::copy_file(from, to);
    } catch (fs::filesystem_error const &ex) {
        std::cout << "what():  " << ex.what() << '\n'
                  << "path1(): " << ex.path1() << '\n'
                  << "path2(): " << ex.path2() << '\n'
                  << "code().value():    " << ex.code().value() << '\n'
                  << "code().message():  " << ex.code().message() << '\n'
                  << "code().category(): " << ex.code().category().name() << '\n';

        try {
            fmt::println("{:s}", ex.code());
        } catch (std::exception &e) {
            fmt::println("fmt error: {}", e.what());
        }
    }

    fmt::println("exit");
    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions