From 8b95516aef0cd4bd98e2592d6f247882dc88886a Mon Sep 17 00:00:00 2001
From: Kelly Rauchenberger <fefferburbia@gmail.com>
Date: Sat, 31 Mar 2018 23:11:20 -0400
Subject: Converted asserts in generator to exceptions

---
 generator/generator.cpp   |  3 +--
 generator/group.cpp       |  4 ++--
 generator/group.h         |  1 -
 generator/lemma.cpp       |  8 +++++---
 generator/pronunciation.h | 14 +++++++++-----
 generator/word.h          | 14 +++++++++-----
 6 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/generator/generator.cpp b/generator/generator.cpp
index 785ec87..e52aa90 100644
--- a/generator/generator.cpp
+++ b/generator/generator.cpp
@@ -242,8 +242,7 @@ namespace verbly {
           {
             adj.setAdjectivePosition(positioning::postnominal);
           } else {
-            // Can't happen because of how we specified the regex.
-            assert(false);
+            throw std::logic_error("adjpos_str invalid");
           }
         }
       }
diff --git a/generator/group.cpp b/generator/group.cpp
index 1ffb9d9..0e609e9 100644
--- a/generator/group.cpp
+++ b/generator/group.cpp
@@ -144,8 +144,8 @@ namespace verbly {
 
             case part::type::invalid:
             {
-              // Invalid parts should not be serialized.
-              assert(false);
+              throw std::invalid_argument(
+                "Invalid parts should not be serialized");
 
               break;
             }
diff --git a/generator/group.h b/generator/group.h
index f912920..c8e30e4 100644
--- a/generator/group.h
+++ b/generator/group.h
@@ -4,7 +4,6 @@
 #include <map>
 #include <set>
 #include <string>
-#include <cassert>
 #include <list>
 #include <hkutil/database.h>
 #include "role.h"
diff --git a/generator/lemma.cpp b/generator/lemma.cpp
index 33ab037..a64e43b 100644
--- a/generator/lemma.cpp
+++ b/generator/lemma.cpp
@@ -1,6 +1,6 @@
 #include "lemma.h"
 #include <list>
-#include <cassert>
+#include <stdexcept>
 #include "form.h"
 
 namespace verbly {
@@ -17,8 +17,10 @@ namespace verbly {
 
     void lemma::addInflection(inflection type, const form& f)
     {
-      // There can only be one base form.
-      assert(type != inflection::base);
+      if (type == inflection::base)
+      {
+        throw std::invalid_argument("There can only be one base form");
+      }
 
       inflections_[type].insert(&f);
     }
diff --git a/generator/pronunciation.h b/generator/pronunciation.h
index 163e55e..3190e6d 100644
--- a/generator/pronunciation.h
+++ b/generator/pronunciation.h
@@ -2,8 +2,8 @@
 #define PRONUNCIATION_H_584A08DD
 
 #include <string>
-#include <cassert>
 #include <hkutil/database.h>
+#include <stdexcept>
 
 namespace verbly {
   namespace generator {
@@ -34,16 +34,20 @@ namespace verbly {
 
       std::string getRhymePhonemes() const
       {
-        // Calling code should always call hasRhyme first.
-        assert(!rhyme_.empty());
+        if (rhyme_.empty())
+        {
+          throw std::domain_error("Pronunciation does not have a rhyme");
+        }
 
         return rhyme_;
       }
 
       std::string getPrerhyme() const
       {
-        // Calling code should always call hasRhyme first.
-        assert(!rhyme_.empty());
+        if (rhyme_.empty())
+        {
+          throw std::domain_error("Pronunciation does not have a rhyme");
+        }
 
         return prerhyme_;
       }
diff --git a/generator/word.h b/generator/word.h
index 2e469d4..2818202 100644
--- a/generator/word.h
+++ b/generator/word.h
@@ -1,7 +1,7 @@
 #ifndef WORD_H_91F99D46
 #define WORD_H_91F99D46
 
-#include <cassert>
+#include <stdexcept>
 #include <hkutil/database.h>
 #include "../lib/enums.h"
 
@@ -61,8 +61,10 @@ namespace verbly {
 
       int getTagCount() const
       {
-        // Calling code should always call hasTagCount first.
-        assert(hasTagCount_);
+        if (!hasTagCount_)
+        {
+          throw std::domain_error("Word does not have a tag count");
+        }
 
         return tagCount_;
       }
@@ -79,8 +81,10 @@ namespace verbly {
 
       const group& getVerbGroup() const
       {
-        // Calling code should always call hasVerbGroup first.
-        assert(verbGroup_ != nullptr);
+        if (!hasVerbGroup())
+        {
+          throw std::domain_error("Word does not have a verb group");
+        }
 
         return *verbGroup_;
       }
-- 
cgit 1.4.1