| 88 | } |
| 89 | |
| 90 | int main(int argc, char* argv[]) |
| 91 | { |
| 92 | if (argc < 2) |
| 93 | { |
| 94 | cout << "Usage: error_demo path\n"; |
| 95 | return 1; |
| 96 | } |
| 97 | |
| 98 | error_code ec; |
| 99 | |
| 100 | //// construct path - no error_code |
| 101 | |
| 102 | //try { path p1(argv[1]); } |
| 103 | //catch (const system_error& ex) |
| 104 | //{ |
| 105 | // cout << "construct path without error_code"; |
| 106 | // report_system_error(ex); |
| 107 | //} |
| 108 | |
| 109 | //// construct path - with error_code |
| 110 | |
| 111 | path p (argv[1]); |
| 112 | |
| 113 | fs::file_status s; |
| 114 | bool b (false); |
| 115 | fs::directory_iterator di; |
| 116 | |
| 117 | // get status - no error_code |
| 118 | |
| 119 | cout << "\nstatus(\"" << p.string() << "\");\n"; |
| 120 | threw_exception = false; |
| 121 | |
| 122 | try { s = fs::status(p); } |
| 123 | catch (const system_error& ex) |
| 124 | { |
| 125 | report_filesystem_error(ex); |
| 126 | threw_exception = true; |
| 127 | } |
| 128 | if (!threw_exception) |
| 129 | cout << " Did not throw exception\n"; |
| 130 | report_status(s); |
| 131 | |
| 132 | // get status - with error_code |
| 133 | |
| 134 | cout << "\nstatus(\"" << p.string() << "\", ec);\n"; |
| 135 | s = fs::status(p, ec); |
| 136 | report_status(s); |
| 137 | report_error_code(ec); |
| 138 | |
| 139 | // query existence - no error_code |
| 140 | |
| 141 | cout << "\nexists(\"" << p.string() << "\");\n"; |
| 142 | threw_exception = false; |
| 143 | |
| 144 | try { b = fs::exists(p); } |
| 145 | catch (const system_error& ex) |
| 146 | { |
| 147 | report_filesystem_error(ex); |
nothing calls this directly
no test coverage detected