Browse Source

[2850] Throw isc::InvalidOperation instead of isc::Unexpected

Mukund Sivaraman 12 years ago
parent
commit
5d65c74c12

+ 12 - 0
src/lib/datasrc/memory/zone_table_segment.h

@@ -96,12 +96,24 @@ public:
     virtual ~ZoneTableSegment() {}
 
     /// \brief Return the ZoneTableHeader for the zone table segment.
+    ///
+    /// \throw isc::InvalidOperation may be thrown by some
+    /// implementations if this method is called without calling
+    /// \c reset() successfully first.
     virtual ZoneTableHeader& getHeader() = 0;
 
     /// \brief const version of \c getHeader().
+    ///
+    /// \throw isc::InvalidOperation may be thrown by some
+    /// implementations if this method is called without calling
+    /// \c reset() successfully first.
     virtual const ZoneTableHeader& getHeader() const = 0;
 
     /// \brief Return the MemorySegment for the zone table segment.
+    ///
+    /// \throw isc::InvalidOperation may be thrown by some
+    /// implementations if this method is called without calling
+    /// \c reset() successfully first.
     virtual isc::util::MemorySegment& getMemorySegment() = 0;
 
     /// \brief Return true if the segment is writable.

+ 3 - 3
src/lib/datasrc/memory/zone_table_segment_mapped.cc

@@ -195,7 +195,7 @@ ZoneTableSegmentMapped::reset(MemorySegmentOpenMode mode,
 ZoneTableHeader&
 ZoneTableSegmentMapped::getHeader() {
     if (!mem_sgmt_) {
-        isc_throw(isc::Unexpected,
+        isc_throw(isc::InvalidOperation,
                   "getHeader() called without calling reset() first");
     }
     return (*header_);
@@ -204,7 +204,7 @@ ZoneTableSegmentMapped::getHeader() {
 const ZoneTableHeader&
 ZoneTableSegmentMapped::getHeader() const {
     if (!mem_sgmt_) {
-        isc_throw(isc::Unexpected,
+        isc_throw(isc::InvalidOperation,
                   "getHeader() called without calling reset() first");
     }
     return (*header_);
@@ -213,7 +213,7 @@ ZoneTableSegmentMapped::getHeader() const {
 MemorySegment&
 ZoneTableSegmentMapped::getMemorySegment() {
     if (!mem_sgmt_) {
-        isc_throw(isc::Unexpected,
+        isc_throw(isc::InvalidOperation,
                   "getMemorySegment() called without calling reset() first");
     }
     return (*mem_sgmt_);

+ 3 - 3
src/lib/datasrc/memory/zone_table_segment_mapped.h

@@ -46,20 +46,20 @@ public:
     /// \brief Return the ZoneTableHeader for the mapped zone table
     /// segment implementation.
     ///
-    /// \throws isc::Unexpected if this method is called without a
+    /// \throws isc::InvalidOperation if this method is called without a
     /// successful \c reset() call first.
     virtual ZoneTableHeader& getHeader();
 
     /// \brief const version of \c getHeader().
     ///
-    /// \throws isc::Unexpected if this method is called without a
+    /// \throws isc::InvalidOperation if this method is called without a
     /// successful \c reset() call first.
     virtual const ZoneTableHeader& getHeader() const;
 
     /// \brief Return the MemorySegment for the memory-mapped zone table
     /// segment implementation (a MemorySegmentMapped instance).
     ///
-    /// \throws isc::Unexpected if this method is called without a
+    /// \throws isc::InvalidOperation if this method is called without a
     /// successful \c reset() call first.
     virtual isc::util::MemorySegment& getMemorySegment();
 

+ 8 - 8
src/lib/datasrc/tests/memory/zone_table_segment_mapped_unittest.cc

@@ -60,12 +60,12 @@ protected:
 
 TEST_F(ZoneTableSegmentMappedTest, getHeaderUninitialized) {
     // This should throw as we haven't called reset() yet.
-    EXPECT_THROW(ztable_segment_->getHeader(), isc::Unexpected);
+    EXPECT_THROW(ztable_segment_->getHeader(), isc::InvalidOperation);
 }
 
 TEST_F(ZoneTableSegmentMappedTest, getMemorySegmentUninitialized) {
     // This should throw as we haven't called reset() yet.
-    EXPECT_THROW(ztable_segment_->getMemorySegment(), isc::Unexpected);
+    EXPECT_THROW(ztable_segment_->getMemorySegment(), isc::InvalidOperation);
 }
 
 TEST_F(ZoneTableSegmentMappedTest, isWritableUninitialized) {
@@ -100,8 +100,8 @@ TEST_F(ZoneTableSegmentMappedTest, resetBadConfig) {
     }, isc::InvalidParameter);
 
     // The following should still throw, unaffected by the failed opens.
-    EXPECT_THROW(ztable_segment_->getHeader(), isc::Unexpected);
-    EXPECT_THROW(ztable_segment_->getMemorySegment(), isc::Unexpected);
+    EXPECT_THROW(ztable_segment_->getHeader(), isc::InvalidOperation);
+    EXPECT_THROW(ztable_segment_->getMemorySegment(), isc::InvalidOperation);
 
     // isWritable() must still return false, because the segment has not
     // been successfully reset() yet.
@@ -117,8 +117,8 @@ TEST_F(ZoneTableSegmentMappedTest, reset) {
     }, MemorySegmentOpenError);
 
     // The following should still throw, unaffected by the failed open.
-    EXPECT_THROW(ztable_segment_->getHeader(), isc::Unexpected);
-    EXPECT_THROW(ztable_segment_->getMemorySegment(), isc::Unexpected);
+    EXPECT_THROW(ztable_segment_->getHeader(), isc::InvalidOperation);
+    EXPECT_THROW(ztable_segment_->getMemorySegment(), isc::InvalidOperation);
 
     // isWritable() must still return false, because the segment has not
     // been successfully reset() yet.
@@ -155,8 +155,8 @@ TEST_F(ZoneTableSegmentMappedTest, reset) {
                                Element::fromJSON("{}"));
     }, isc::InvalidParameter);
     // The following should throw now.
-    EXPECT_THROW(ztable_segment_->getHeader(), isc::Unexpected);
-    EXPECT_THROW(ztable_segment_->getMemorySegment(), isc::Unexpected);
+    EXPECT_THROW(ztable_segment_->getHeader(), isc::InvalidOperation);
+    EXPECT_THROW(ztable_segment_->getMemorySegment(), isc::InvalidOperation);
 
     // isWritable() must return false, because the last reset() failed.
     EXPECT_FALSE(ztable_segment_->isWritable());