From 83285a297aa3d60f25948a9e3aa25c7ee3d78259 Mon Sep 17 00:00:00 2001 From: Leonetienne Date: Wed, 2 Jun 2021 22:27:51 +0200 Subject: [PATCH] Added custom Exception HazelnuppValueNotConvertibleException --- Hazelnupp/FloatValue.cpp | 5 +++-- Hazelnupp/FloatValue.h | 2 +- Hazelnupp/HazelnuppException.h | 7 +++++++ Hazelnupp/IntValue.cpp | 3 ++- Hazelnupp/IntValue.h | 2 +- Hazelnupp/ListValue.cpp | 11 ++++++----- Hazelnupp/ListValue.h | 10 +++++----- Hazelnupp/StringValue.cpp | 11 ++++++----- Hazelnupp/StringValue.h | 10 +++++----- Hazelnupp/VoidValue.cpp | 13 +++++++------ Hazelnupp/VoidValue.h | 12 ++++++------ 11 files changed, 49 insertions(+), 37 deletions(-) diff --git a/Hazelnupp/FloatValue.cpp b/Hazelnupp/FloatValue.cpp index ff001ec..61e63f9 100644 --- a/Hazelnupp/FloatValue.cpp +++ b/Hazelnupp/FloatValue.cpp @@ -1,4 +1,5 @@ #include "FloatValue.h" +#include "HazelnuppException.h" #include FloatValue::FloatValue(const long double& value) @@ -68,5 +69,5 @@ std::string FloatValue::GetString() const const std::vector& FloatValue::GetList() const { - throw std::bad_cast(); -} \ No newline at end of file + throw HazelnuppValueNotConvertibleException(); +} diff --git a/Hazelnupp/FloatValue.h b/Hazelnupp/FloatValue.h index 79a03f6..816d233 100644 --- a/Hazelnupp/FloatValue.h +++ b/Hazelnupp/FloatValue.h @@ -33,7 +33,7 @@ public: //! Will return the data as a string std::string GetString() const override; - //! Throws std::bad_cast + //! Throws HazelnuppValueNotConvertibleException const std::vector& GetList() const override; private: diff --git a/Hazelnupp/HazelnuppException.h b/Hazelnupp/HazelnuppException.h index ff04ba8..1b616c0 100644 --- a/Hazelnupp/HazelnuppException.h +++ b/Hazelnupp/HazelnuppException.h @@ -26,6 +26,13 @@ public: HazelnuppInvalidKeyException(const std::string& msg) : HazelnuppException(msg) {}; }; +class HazelnuppValueNotConvertibleException : public HazelnuppException +{ +public: + HazelnuppValueNotConvertibleException() : HazelnuppException() {}; + HazelnuppValueNotConvertibleException(const std::string& msg) : HazelnuppException(msg) {}; +}; + class HazelnuppConstraintException : public HazelnuppException { public: diff --git a/Hazelnupp/IntValue.cpp b/Hazelnupp/IntValue.cpp index 3399f12..1d1d1da 100644 --- a/Hazelnupp/IntValue.cpp +++ b/Hazelnupp/IntValue.cpp @@ -1,4 +1,5 @@ #include "IntValue.h" +#include "HazelnuppException.h" #include IntValue::IntValue(const long long int& value) @@ -68,5 +69,5 @@ std::string IntValue::GetString() const const std::vector& IntValue::GetList() const { - throw std::bad_cast(); + throw HazelnuppValueNotConvertibleException(); } diff --git a/Hazelnupp/IntValue.h b/Hazelnupp/IntValue.h index 53855ea..4461d9d 100644 --- a/Hazelnupp/IntValue.h +++ b/Hazelnupp/IntValue.h @@ -33,7 +33,7 @@ public: //! Will return the data as a string std::string GetString() const override; - //! Throws std::bad_cast + //! Throws HazelnuppValueNotConvertibleException const std::vector& GetList() const override; private: diff --git a/Hazelnupp/ListValue.cpp b/Hazelnupp/ListValue.cpp index a0f16da..15f9efd 100644 --- a/Hazelnupp/ListValue.cpp +++ b/Hazelnupp/ListValue.cpp @@ -1,4 +1,5 @@ #include "ListValue.h" +#include "HazelnuppException.h" #include ListValue::ListValue() : @@ -65,27 +66,27 @@ ListValue::operator std::vector() const long long int ListValue::GetInt64() const { - throw std::bad_cast(); + throw HazelnuppValueNotConvertibleException(); } int ListValue::GetInt32() const { - throw std::bad_cast(); + throw HazelnuppValueNotConvertibleException(); } long double ListValue::GetFloat64() const { - throw std::bad_cast(); + throw HazelnuppValueNotConvertibleException(); } double ListValue::GetFloat32() const { - throw std::bad_cast(); + throw HazelnuppValueNotConvertibleException(); } std::string ListValue::GetString() const { - throw std::bad_cast(); + throw HazelnuppValueNotConvertibleException(); } const std::vector& ListValue::GetList() const diff --git a/Hazelnupp/ListValue.h b/Hazelnupp/ListValue.h index 1ecfe9a..9c10d90 100644 --- a/Hazelnupp/ListValue.h +++ b/Hazelnupp/ListValue.h @@ -22,17 +22,17 @@ public: operator std::vector() const; - //! Throws std::bad_cast + //! Throws HazelnuppValueNotConvertibleException long long int GetInt64() const override; - //! Throws std::bad_cast + //! Throws HazelnuppValueNotConvertibleException int GetInt32() const override; - //! Throws std::bad_cast + //! Throws HazelnuppValueNotConvertibleException long double GetFloat64() const override; - //! Throws std::bad_cast + //! Throws HazelnuppValueNotConvertibleException double GetFloat32() const override; - //! Throws std::bad_cast + //! Throws HazelnuppValueNotConvertibleException std::string GetString() const override; //! Will return this values list diff --git a/Hazelnupp/StringValue.cpp b/Hazelnupp/StringValue.cpp index 17ba858..c7bfb53 100644 --- a/Hazelnupp/StringValue.cpp +++ b/Hazelnupp/StringValue.cpp @@ -1,4 +1,5 @@ #include "StringValue.h" +#include "HazelnuppException.h" #include StringValue::StringValue(const std::string& value) @@ -35,22 +36,22 @@ StringValue::operator std::string() const long long int StringValue::GetInt64() const { - throw std::bad_cast(); + throw HazelnuppValueNotConvertibleException(); } int StringValue::GetInt32() const { - throw std::bad_cast(); + throw HazelnuppValueNotConvertibleException(); } long double StringValue::GetFloat64() const { - throw std::bad_cast(); + throw HazelnuppValueNotConvertibleException(); } double StringValue::GetFloat32() const { - throw std::bad_cast(); + throw HazelnuppValueNotConvertibleException(); } std::string StringValue::GetString() const @@ -60,5 +61,5 @@ std::string StringValue::GetString() const const std::vector& StringValue::GetList() const { - throw std::bad_cast(); + throw HazelnuppValueNotConvertibleException(); } diff --git a/Hazelnupp/StringValue.h b/Hazelnupp/StringValue.h index 937e11b..2fc7ad5 100644 --- a/Hazelnupp/StringValue.h +++ b/Hazelnupp/StringValue.h @@ -19,20 +19,20 @@ public: operator std::string() const; - //! Throws std::bad_cast + //! Throws HazelnuppValueNotConvertibleException long long int GetInt64() const override; - //! Throws std::bad_cast + //! Throws HazelnuppValueNotConvertibleException int GetInt32() const override; - //! Throws std::bad_cast + //! Throws HazelnuppValueNotConvertibleException long double GetFloat64() const override; - //! Throws std::bad_cast + //! Throws HazelnuppValueNotConvertibleException double GetFloat32() const override; //! Will return this value as a string std::string GetString() const override; - //! Throws std::bad_cast + //! Throws HazelnuppValueNotConvertibleException const std::vector& GetList() const override; private: diff --git a/Hazelnupp/VoidValue.cpp b/Hazelnupp/VoidValue.cpp index b3671ad..e119c39 100644 --- a/Hazelnupp/VoidValue.cpp +++ b/Hazelnupp/VoidValue.cpp @@ -1,4 +1,5 @@ #include "VoidValue.h" +#include "HazelnuppException.h" VoidValue::VoidValue() : @@ -21,30 +22,30 @@ std::string VoidValue::GetAsOsString() const long long int VoidValue::GetInt64() const { - throw std::bad_cast(); + throw HazelnuppValueNotConvertibleException(); } int VoidValue::GetInt32() const { - throw std::bad_cast(); + throw HazelnuppValueNotConvertibleException(); } long double VoidValue::GetFloat64() const { - throw std::bad_cast(); + throw HazelnuppValueNotConvertibleException(); } double VoidValue::GetFloat32() const { - throw std::bad_cast(); + throw HazelnuppValueNotConvertibleException(); } std::string VoidValue::GetString() const { - throw std::bad_cast(); + throw HazelnuppValueNotConvertibleException(); } const std::vector& VoidValue::GetList() const { - throw std::bad_cast(); + throw HazelnuppValueNotConvertibleException(); } diff --git a/Hazelnupp/VoidValue.h b/Hazelnupp/VoidValue.h index 967c001..ec48a1c 100644 --- a/Hazelnupp/VoidValue.h +++ b/Hazelnupp/VoidValue.h @@ -13,19 +13,19 @@ public: //! Will return a string suitable for an std::ostream; std::string GetAsOsString() const override; - //! Throws std::bad_cast + //! Throws HazelnuppValueNotConvertibleException long long int GetInt64() const override; - //! Throws std::bad_cast + //! Throws HazelnuppValueNotConvertibleException int GetInt32() const override; - //! Throws std::bad_cast + //! Throws HazelnuppValueNotConvertibleException long double GetFloat64() const override; - //! Throws std::bad_cast + //! Throws HazelnuppValueNotConvertibleException double GetFloat32() const override; - //! Throws std::bad_cast + //! Throws HazelnuppValueNotConvertibleException std::string GetString() const override; - //! Throws std::bad_cast + //! Throws HazelnuppValueNotConvertibleException const std::vector& GetList() const; };