From cb6f31b3a077ab3591d5d2d68dfa8354e80d632f 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 8502f3a8..57800d85 100644 --- a/src/DataTree.hh +++ b/src/DataTree.hh @@ -302,9 +302,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 @@ -353,10 +357,14 @@ public: return false; }; - struct UnknownLocalVariableException + class UnknownLocalVariableException : public std::exception { + private: //! Symbol ID int id; + + public: + UnknownLocalVariableException(int id_arg) : id(id_arg) {} }; [[nodiscard]] expr_t diff --git a/src/EquationTags.hh b/src/EquationTags.hh index 998857cb..e08bcab7 100644 --- a/src/EquationTags.hh +++ b/src/EquationTags.hh @@ -33,6 +33,18 @@ 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 40aadb51..2815b153 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 01bbf91f..7adbca7f 100644 --- a/src/SymbolTable.hh +++ b/src/SymbolTable.hh @@ -152,36 +152,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