- filesystem[meta header]
- std::filesystem[meta namespace]
- filesystem_error[meta class]
- function[meta id-type]
- cpp17[meta cpp]
filesystem_error(const string& what_arg,
error_code ec); // (1)
filesystem_error(const string& what_arg,
const path& p1,
error_code ec); // (2)
filesystem_error(const string& what_arg,
const path& p1,
const path& p2,
error_code ec); // (3)
- string[link /reference/string/basic_string.md]
- error_code[link /reference/system_error/error_code.md]
- path[link /reference/filesystem/path.md]
- (1) : エラー理由の文字列と、エラーコードを受け取るコンストラクタ
- (2) : エラー理由の文字列、エラーとなったパス、エラーコードを受け取るコンストラクタ
- (3) : エラー理由の文字列、エラーとなったパスを一組と、エラーコードを受け取るコンストラクタ
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
// (1)
try {
throw fs::filesystem_error(
"can't copy file. source file doesn't found",
std::make_error_code(std::errc::no_such_file_or_directory)
);
}
catch (fs::filesystem_error& err) {
std::cout << err.what() << std::endl;
}
// (2)
try {
throw fs::filesystem_error(
"can't copy file. source file doesn't found",
"a/b.txt",
std::make_error_code(std::errc::no_such_file_or_directory)
);
}
catch (fs::filesystem_error& err) {
std::cout << err.what() << std::endl;
}
// (3)
try {
throw fs::filesystem_error(
"can't copy file. source file doesn't found",
"a/from.txt",
"b/to.txt",
std::make_error_code(std::errc::no_such_file_or_directory)
);
}
catch (fs::filesystem_error& err) {
std::cout << err.what() << std::endl;
}
}
- std::make_error_code[link /reference/system_error/make_error_code.md]
- std::errc::no_such_file_or_directory[link /reference/system_error/errc.md]
- err.what()[link what.md]
filesystem error: can't copy file. source file doesn't found: No such file or directory
filesystem error: can't copy file. source file doesn't found: No such file or directory [a/b.txt]
filesystem error: can't copy file. source file doesn't found: No such file or directory [a/from.txt] [b/to.txt]