Browse Source

[2369] Throw a custom exception in ungetChar()

Mukund Sivaraman 12 years ago
parent
commit
a6093a8ef8
3 changed files with 13 additions and 4 deletions
  1. 1 2
      src/lib/dns/inputsource.cc
  2. 10 0
      src/lib/dns/inputsource.h
  3. 2 2
      src/lib/dns/tests/inputsource_unittest.cc

+ 1 - 2
src/lib/dns/inputsource.cc

@@ -13,7 +13,6 @@
 // PERFORMANCE OF THIS SOFTWARE.
 
 #include <dns/inputsource.h>
-#include <exceptions/exceptions.h>
 
 namespace isc {
 namespace dns {
@@ -53,7 +52,7 @@ InputSource::ungetChar() {
     if (at_eof_) {
         at_eof_ = false;
     } else if (buffer_pos_ == 0) {
-        isc_throw(OutOfRange, "Cannot skip before the start of buffer");
+        isc_throw(UngetError, "Cannot skip before the start of buffer");
     } else {
         buffer_pos_--;
         if (buffer_[buffer_pos_] == '\n') {

+ 10 - 0
src/lib/dns/inputsource.h

@@ -15,6 +15,8 @@
 #ifndef DNS_INPUTSOURCE_H
 #define DNS_INPUTSOURCE_H 1
 
+#include <exceptions/exceptions.h>
+
 #include <iostream>
 #include <string>
 #include <vector>
@@ -50,6 +52,14 @@ public:
         saved_line_ = line_;
     }
 
+    /// \brief Exception thrown when ungetChar() is made to go before
+    /// the start of buffer.
+    struct UngetError : public OutOfRange {
+        UngetError(const char* file, size_t line, const char* what) :
+            OutOfRange(file, line, what)
+        {}
+    };
+
     int getChar();
     void ungetChar();
     void ungetAll();

+ 2 - 2
src/lib/dns/tests/inputsource_unittest.cc

@@ -96,7 +96,7 @@ TEST_F(InputSourceTest, getAndUngetChar) {
     }
 
     // Skipping past the start of buffer should throw.
-    EXPECT_THROW(source_.ungetChar(), isc::OutOfRange);
+    EXPECT_THROW(source_.ungetChar(), InputSource::UngetError);
 }
 
 // ungetAll() should skip back to the place where the InputSource
@@ -162,7 +162,7 @@ TEST_F(InputSourceTest, lines) {
                          ((line - 1) == source_.getCurrentLine())));
             line = source_.getCurrentLine();
         }
-    }, isc::OutOfRange);
+    }, InputSource::UngetError);
 
     // Now we are back to where we started.
     EXPECT_EQ(1, source_.getCurrentLine());