File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -50,11 +50,18 @@ namespace matplot {
5050 iequals (str, " no" );
5151 }
5252
53+ struct pipe_deleter {
54+ int operator ()(FILE* pipe) const {
55+ if (int status = PCLOSE (pipe); status != -1 )
56+ return status;
57+ throw std::system_error{errno, std::system_category (), " pclose" };
58+ }
59+ };
60+
5361 std::string run_and_get_output (const std::string &cmd) {
54- std::unique_ptr<FILE, int (*)(FILE *)> pipe (POPEN (cmd.c_str (), " r" ),
55- PCLOSE);
62+ std::unique_ptr<FILE, pipe_deleter> pipe (POPEN (cmd.c_str (), " r" ));
5663 if (!pipe) {
57- throw std::runtime_error ( " popen() failed! " ) ;
64+ throw std::system_error{errno, std::system_category (), cmd} ;
5865 }
5966 std::array<char , 128 > buffer{};
6067 std::string result;
@@ -363,7 +370,7 @@ namespace matplot {
363370 std::string fileread (const std::string &filename) {
364371 std::ifstream t (filename);
365372 if (!t) {
366- throw std::runtime_error ( " Cannot open the file " + filename);
373+ throw std::system_error (errno, std::system_category (), filename);
367374 }
368375 std::string str ((std::istreambuf_iterator<char >(t)),
369376 std::istreambuf_iterator<char >());
You can’t perform that action at this time.
0 commit comments