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)
概要
- (1) : エラー理由の文字列と、エラーコードを受け取るコンストラクタ
- (2) : エラー理由の文字列、エラーとなったパス、エラーコードを受け取るコンストラクタ
- (3) : エラー理由の文字列、エラーとなったパスを一組と、エラーコードを受け取るコンストラクタ
事後条件
- (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;
}
}
出力例
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]
バージョン
言語
- C++17
処理系
- Clang:
- GCC: 4.8.1
- Visual C++:
参照
- LWG Issue
system_error
andfilesystem_error
constructors taking astring
may not be able to meet their postconditions- C++20でのエラー理由文字列の事後条件が、指定したエラー理由文字列を直接要求するのではなく、それを含んでいることを要求するように変更された