From 49138b39474230ff18c992c1b640773ee75ebf4b Mon Sep 17 00:00:00 2001
From: MichelJuillard <michel.juillard@mjui.fr>
Date: Sun, 6 Nov 2022 10:15:02 +0100
Subject: [PATCH] Exception class instead of struct

---
 src/DataTree.hh               | 14 ++++++++++---
 src/EquationTags.hh           | 12 ++++++++++++
 src/ExternalFunctionsTable.hh |  6 +++++-
 src/SymbolTable.hh            | 37 ++++++++++++++++++++++++++++++-----
 4 files changed, 60 insertions(+), 9 deletions(-)

diff --git a/src/DataTree.hh b/src/DataTree.hh
index 8afab57c..1319fee2 100644
--- a/src/DataTree.hh
+++ b/src/DataTree.hh
@@ -287,9 +287,13 @@ public:
   };
 
   //! Raised when a trend is declared twice
-  struct TrendException
+  class TrendException : public std::exception
   {
-    string name;
+  private: 
+    const string name;
+
+  public:
+    TrendException(string name_arg) : name(name_arg) {}
   };
 
   // Returns the derivation ID, or throws an exception if the derivation ID does not exist
@@ -337,10 +341,14 @@ public:
     return false;
   };
 
-  struct UnknownLocalVariableException
+  class UnknownLocalVariableException : public std::exception
   {
+  private: 
     //! Symbol ID
     int id;
+
+  public:
+    UnknownLocalVariableException(int id_arg) : id(id_arg) {}
   };
 
   expr_t
diff --git a/src/EquationTags.hh b/src/EquationTags.hh
index 9ac418bd..befe2042 100644
--- a/src/EquationTags.hh
+++ b/src/EquationTags.hh
@@ -32,6 +32,18 @@ class EquationTags
 private:
   map<int, map<string, string>> eqn_tags;
 public:
+  class TagNotFoundException : public std::exception
+  {
+  private: 
+    const string key, value;
+
+  public:
+    TagNotFoundException(const string key_arg, const string value_arg) : key(key_arg),
+									 value(value_arg)
+    {
+    }
+  };
+
   // Add multiple equation tags for the given equation
   void
   add(int eqn, map<string, string> tags)
diff --git a/src/ExternalFunctionsTable.hh b/src/ExternalFunctionsTable.hh
index 39fbd67f..3d9626f9 100644
--- a/src/ExternalFunctionsTable.hh
+++ b/src/ExternalFunctionsTable.hh
@@ -33,10 +33,14 @@ class ExternalFunctionsTable
 {
 public:
   //! Thrown when trying to access an unknown symbol (by id)
-  struct UnknownExternalFunctionSymbolIDException
+  class UnknownExternalFunctionSymbolIDException : public std::exception
   {
+  private: 
     //! Symbol ID
     int id;
+
+  public:
+    UnknownExternalFunctionSymbolIDException(int id_arg) : id(id_arg) {}
   };
 
   /* For all arguments, -2 means not set
diff --git a/src/SymbolTable.hh b/src/SymbolTable.hh
index 818334fc..cce17027 100644
--- a/src/SymbolTable.hh
+++ b/src/SymbolTable.hh
@@ -148,36 +148,63 @@ private:
 
 public:
   //! Thrown when trying to access an unknown symbol (by name)
-  struct UnknownSymbolNameException
+  class UnknownSymbolNameException : public std::exception
   {
+  private: 
     //! Symbol name
     const string name;
+
+  public:
+    UnknownSymbolNameException(const string name_arg) : name(name_arg) {}
   };
   //! Thrown when trying to access an unknown symbol (by id)
-  struct UnknownSymbolIDException
+  class UnknownSymbolIDException : public std::exception
   {
+  private: 
     //! Symbol ID
     const int id;
+
+  public:
+    UnknownSymbolIDException(const int id_arg) : id(id_arg) {}
   };
   //! Thrown when trying to access an unknown type specific ID
-  struct UnknownTypeSpecificIDException
+  class UnknownTypeSpecificIDException : public std::exception
   {
+  private: 
     const int tsid;
     const SymbolType type;
+
+  public:
+    UnknownTypeSpecificIDException(int tsid_arg, SymbolType type_arg) : tsid(tsid_arg),
+									type(type_arg)
+    {
+    }
   };
   /* Thrown when requesting the type specific ID of a symbol which doesn’t
      have one */
-  struct NoTypeSpecificIDException
+  class NoTypeSpecificIDException : public std::exception
   {
+  private: 
+    //! Symbol ID
     const int symb_id;
+
+  public:
+    NoTypeSpecificIDException(int symb_id_arg) : symb_id(symb_id_arg) {}
   };
   //! Thrown when trying to declare a symbol twice
-  struct AlreadyDeclaredException
+  class AlreadyDeclaredException : public std::exception
   {
+  private: 
     //! Symbol name
     const string name;
     //! Was the previous declaration done with the same symbol type ?
     const bool same_type;
+
+  public:
+    AlreadyDeclaredException(string name_arg, bool same_type_arg) : name(name_arg),
+								    same_type(same_type_arg)
+    {
+    }
   };
   //! Thrown when table is frozen and trying to modify it
   class FrozenException
-- 
GitLab