From b0bf7561a6e85ea913d45cd732cf3e1f7abc3b43 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 21 Jan 2015 14:32:02 +0000 Subject: Throw specific exception (NoRowsFound) when a row is required but none are returned --- p2pvr/daemon/sqlSelectDeserializer.cpp | 6 +++--- p2pvr/daemon/sqlSelectDeserializer.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/p2pvr/daemon/sqlSelectDeserializer.cpp b/p2pvr/daemon/sqlSelectDeserializer.cpp index 8217f1e..3f011a4 100644 --- a/p2pvr/daemon/sqlSelectDeserializer.cpp +++ b/p2pvr/daemon/sqlSelectDeserializer.cpp @@ -103,7 +103,7 @@ SqlSelectDeserializer::DeserializeSimple(Slicer::ModelPartPtr mp) { auto fmp = mp->GetAnonChild(); if (!cmd.fetch()) { - std::invalid_argument("No rows returned"); + throw NoRowsReturned(); } SqlSourcePtr h = new SqlSource(); const DB::Column & c = cmd[0]; @@ -114,7 +114,7 @@ SqlSelectDeserializer::DeserializeSimple(Slicer::ModelPartPtr mp) fmp->Complete(); } if (cmd.fetch()) { - std::invalid_argument("Too many rows returned"); + throw std::invalid_argument("Too many rows returned"); } } @@ -132,7 +132,7 @@ void SqlSelectDeserializer::DeserializeObject(Slicer::ModelPartPtr mp) { if (!cmd.fetch()) { - throw std::invalid_argument("No rows returned"); + throw NoRowsReturned(); } DeserializeRow(mp); if (cmd.fetch()) { diff --git a/p2pvr/daemon/sqlSelectDeserializer.h b/p2pvr/daemon/sqlSelectDeserializer.h index 008a87c..0c32811 100644 --- a/p2pvr/daemon/sqlSelectDeserializer.h +++ b/p2pvr/daemon/sqlSelectDeserializer.h @@ -4,6 +4,8 @@ #include #include +class NoRowsReturned : public std::exception { }; + class SqlSelectDeserializer : public Slicer::Deserializer { public: SqlSelectDeserializer(DB::SelectCommand &, IceUtil::Optional typeIdCol = IceUtil::Optional()); -- cgit v1.2.3