From 9cfb7dbe44d198fb859635217344a90b1bb9f012 Mon Sep 17 00:00:00 2001 From: randomdan Date: Wed, 8 Sep 2010 01:47:02 +0000 Subject: Add some error handling to ProcRows --- project2/procRows.cpp | 12 +++++++++++- project2/procRows.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/project2/procRows.cpp b/project2/procRows.cpp index f4d0f50..e5ed86a 100644 --- a/project2/procRows.cpp +++ b/project2/procRows.cpp @@ -25,7 +25,17 @@ _ProcRows::doOpen() const if (!f) { throw std::runtime_error("Could not open file"); } - return FileStarChannel(f, false, pclose); + return FileStarChannel(f, false, doClose); +} + +int +_ProcRows::doClose(FILE * f) +{ + int pclo = pclose(f); + if (pclo != 0) { + throw std::runtime_error("Subprocess returned an error"); + } + return 0; } #include "view.hpp" diff --git a/project2/procRows.h b/project2/procRows.h index 02add07..e28a5f5 100644 --- a/project2/procRows.h +++ b/project2/procRows.h @@ -10,6 +10,7 @@ class _ProcRows : public _FileRows { virtual void loadComplete(); virtual FileStarChannel doOpen() const; + static int doClose(FILE*); }; typedef _GenericView<_ProcRows> _ProcView; typedef _GenericIterate<_ProcRows> _ProcIterate; -- cgit v1.2.3