Added custom Exception HazelnuppValueNotConvertibleException

This commit is contained in:
Leonetienne 2021-06-02 22:27:51 +02:00
parent dbc02fab2e
commit 83285a297a
11 changed files with 49 additions and 37 deletions

View File

@ -1,4 +1,5 @@
#include "FloatValue.h"
#include "HazelnuppException.h"
#include <sstream>
FloatValue::FloatValue(const long double& value)
@ -68,5 +69,5 @@ std::string FloatValue::GetString() const
const std::vector<Value*>& FloatValue::GetList() const
{
throw std::bad_cast();
throw HazelnuppValueNotConvertibleException();
}

View File

@ -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<Value*>& GetList() const override;
private:

View File

@ -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:

View File

@ -1,4 +1,5 @@
#include "IntValue.h"
#include "HazelnuppException.h"
#include <sstream>
IntValue::IntValue(const long long int& value)
@ -68,5 +69,5 @@ std::string IntValue::GetString() const
const std::vector<Value*>& IntValue::GetList() const
{
throw std::bad_cast();
throw HazelnuppValueNotConvertibleException();
}

View File

@ -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<Value*>& GetList() const override;
private:

View File

@ -1,4 +1,5 @@
#include "ListValue.h"
#include "HazelnuppException.h"
#include <sstream>
ListValue::ListValue() :
@ -65,27 +66,27 @@ ListValue::operator std::vector<Value*>() 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<Value*>& ListValue::GetList() const

View File

@ -22,17 +22,17 @@ public:
operator std::vector<Value*>() 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

View File

@ -1,4 +1,5 @@
#include "StringValue.h"
#include "HazelnuppException.h"
#include <sstream>
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<Value*>& StringValue::GetList() const
{
throw std::bad_cast();
throw HazelnuppValueNotConvertibleException();
}

View File

@ -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<Value*>& GetList() const override;
private:

View File

@ -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<Value*>& VoidValue::GetList() const
{
throw std::bad_cast();
throw HazelnuppValueNotConvertibleException();
}

View File

@ -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<Value*>& GetList() const;
};