Procházet zdrojové kódy

Improve IllegalArgumentException usage in project classes

Patrick-Christopher Mattulat před 1 rokem
rodič
revize
a955d64975

+ 2 - 2
source/ls-std/boxing/Boolean.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-09
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
@@ -72,7 +72,7 @@ void ls::std::boxing::Boolean::parse(::std::string _parseText)
 
   if (_parseText != this->TRUE_STRING && _parseText != this->FALSE_STRING)
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{_parseText + " is not a valid string representation"};
   }
   else
   {

+ 2 - 2
source/ls-std/boxing/Double.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-14
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
@@ -226,7 +226,7 @@ void ls::std::boxing::Double::_assignEpsilon(double _epsilon)
 {
   if (_epsilon <= 0.0)
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_epsilon is less than or equal zero"};
   }
 
   this->epsilon = _epsilon;

+ 2 - 2
source/ls-std/boxing/Float.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-14
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
@@ -222,7 +222,7 @@ void ls::std::boxing::Float::_assignEpsilon(float _epsilon)
 {
   if (_epsilon <= 0.0)
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"epsilon is less than or equal zero"};
   }
 
   this->epsilon = _epsilon;

+ 1 - 2
source/ls-std/boxing/String.cpp

@@ -3,13 +3,12 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-14
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
 #include <algorithm>
 #include <ls-std/boxing/String.hpp>
-#include <ls-std/core/exception/IllegalArgumentException.hpp>
 
 ls::std::boxing::String::String() : ls::std::core::Class("String")
 {}

+ 2 - 2
source/ls-std/core/Class.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-07
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
@@ -26,7 +26,7 @@ void ls::std::core::Class::_assignClassName(const ::std::string &_name)
 {
   if (_name.empty())
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_name is empty"};
   }
 
   this->name = _name;

+ 2 - 2
source/ls-std/event/Event.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-26
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
@@ -58,7 +58,7 @@ void ls::std::event::Event::_assignId(const ls::std::core::type::event_id &_id)
 {
   if (_id.empty())
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_id is empty"};
   }
 
   this->id = _id;

+ 2 - 2
source/ls-std/event/EventHandler.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-27
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
@@ -26,7 +26,7 @@ void ls::std::event::EventHandler::_assignId(const ls::std::core::type::event_id
 {
   if (_id.empty())
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_id is empty"};
   }
 
   this->id = _id;

+ 17 - 7
source/ls-std/event/EventManager.cpp

@@ -19,9 +19,14 @@ ls::std::event::EventManager::~EventManager() = default;
 
 void ls::std::event::EventManager::subscribe(const ls::std::core::type::event_id &_id, const ::std::shared_ptr<ls::std::core::interface_type::IListener> &_listener)
 {
-  if (_id.empty() || _listener == nullptr)
+  if (_id.empty())
+  {
+    throw ls::std::core::IllegalArgumentException{"_id is empty"};
+  }
+
+  if (_listener == nullptr)
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_listener is null"};
   }
 
   if (this->_hasEventHandler(_id))
@@ -36,9 +41,14 @@ void ls::std::event::EventManager::subscribe(const ls::std::core::type::event_id
 
 void ls::std::event::EventManager::unsubscribe(const ls::std::core::type::event_id &_id, const ::std::shared_ptr<ls::std::core::interface_type::IListener> &_listener)
 {
-  if (_id.empty() || _listener == nullptr)
+  if (_id.empty())
+  {
+    throw ls::std::core::IllegalArgumentException{"_id is empty"};
+  }
+
+  if (_listener == nullptr)
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_listener is null"};
   }
 
   if (this->_hasEventHandler(_id))
@@ -53,7 +63,7 @@ bool ls::std::event::EventManager::addEventHandler(const ::std::shared_ptr<ls::s
 
   if (_eventHandler == nullptr)
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_eventHandler is null"};
   }
 
   if (!this->_hasEventHandler(_eventHandler->getId()))
@@ -81,7 +91,7 @@ bool ls::std::event::EventManager::hasEventHandler(const ls::std::core::type::ev
 {
   if (_id.empty())
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_id is empty"};
   }
 
   return this->_hasEventHandler(_id);
@@ -91,7 +101,7 @@ bool ls::std::event::EventManager::removeEventHandler(const ::std::shared_ptr<ls
 {
   if (_eventHandler == nullptr)
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_eventHandler is null"};
   }
 
   return this->_removeEventHandler(_eventHandler);

+ 3 - 3
source/ls-std/event/Narrator.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-14
- * Changed:         2023-02-06
+ * Changed:         2023-02-07
  *
  * */
 
@@ -22,7 +22,7 @@ bool ls::std::event::Narrator::addListener(const ::std::shared_ptr<ls::std::core
 
   if (_listener == nullptr)
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_listener is null"};
   }
   else
   {
@@ -52,7 +52,7 @@ bool ls::std::event::Narrator::removeListener(const ::std::shared_ptr<ls::std::c
 
   if (_listener == nullptr)
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_listener is null"};
   }
   else
   {

+ 2 - 2
source/ls-std/event/serialization/SerializableJsonEvent.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-12-07
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
@@ -45,7 +45,7 @@ void ls::std::event::SerializableJsonEvent::_assignValue(const ::std::shared_ptr
 {
   if (_value == nullptr)
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_value is null"};
   }
 
   this->value = _value;

+ 3 - 3
source/ls-std/io/kv/KvFileReader.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-12-25
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
@@ -47,7 +47,7 @@ void ls::std::io::KvFileReader::_assignDocument(const ::std::shared_ptr<ls::std:
 {
   if (_document == nullptr)
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_document is null"};
   }
 
   this->document = _document;
@@ -57,7 +57,7 @@ void ls::std::io::KvFileReader::_assignFile(ls::std::io::File _kvFile)
 {
   if (!_kvFile.exists())
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"file does not exist: " + _kvFile.getAbsoluteFilePath()};
   }
 
   this->kvFile = _kvFile;

+ 2 - 2
source/ls-std/io/kv/KvPair.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-12-25
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
@@ -36,7 +36,7 @@ void ls::std::io::KvPair::_assignKey(const ls::std::core::type::kv_key &_key)
 {
   if (_key.empty())
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_key is empty"};
   }
 
   this->key = _key;

+ 2 - 2
source/ls-std/io/kv/KvParser.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-12-25
- * Changed:         2023-02-05
+ * Changed:         2023-02-07
  *
  * */
 
@@ -37,7 +37,7 @@ void ls::std::io::KvParser::_assignDocument(const ::std::shared_ptr<ls::std::io:
 {
   if (_document == nullptr)
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_document is null"};
   }
 
   this->document = _document;

+ 2 - 2
source/ls-std/io/logging/LogLevel.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-20
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
@@ -71,7 +71,7 @@ void ls::std::io::LogLevel::setLogLevel(const ::std::string &_value)
   }
   else
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{_value + " is not a valid log level string"};
   }
 }
 

+ 2 - 2
source/ls-std/io/logging/Logger.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-20
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
@@ -85,7 +85,7 @@ void ls::std::io::Logger::_assignWriter(const ::std::shared_ptr<ls::std::core::i
 {
   if (_writer == nullptr)
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_writer is null"};
   }
 
   this->writer = _writer;

+ 3 - 3
source/ls-std/io/xml/XmlAttribute.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-23
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
@@ -46,7 +46,7 @@ void ls::std::io::XmlAttribute::_assignName(const ::std::string &_name)
 {
   if (_name.empty())
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_name is empty"};
   }
 
   this->name = _name;
@@ -56,7 +56,7 @@ void ls::std::io::XmlAttribute::_assignValue(const ::std::string &_value)
 {
   if (_value.empty())
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_value is empty"};
   }
 
   this->value = _value;

+ 3 - 3
source/ls-std/io/xml/XmlDocument.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-30
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
@@ -56,7 +56,7 @@ void ls::std::io::XmlDocument::_assignDeclaration(const ::std::shared_ptr<ls::st
 {
   if (_declaration == nullptr)
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_declaration is null"};
   }
 
   this->declaration = _declaration;
@@ -66,7 +66,7 @@ void ls::std::io::XmlDocument::_assignRootElement(const ::std::shared_ptr<ls::st
 {
   if (_rootElement == nullptr)
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_rootElement is null"};
   }
 
   this->rootElement = _rootElement;

+ 8 - 8
source/ls-std/io/xml/XmlNode.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-09-24
- * Changed:         2023-02-06
+ * Changed:         2023-02-07
  *
  * */
 
@@ -312,7 +312,7 @@ void ls::std::io::XmlNode::_assignName(const ::std::string &_name)
 {
   if (_name.empty())
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_name is empty"};
   }
 
   this->name = _name;
@@ -322,7 +322,7 @@ void ls::std::io::XmlNode::_assignValue(const ::std::string &_value)
 {
   if (_value.empty())
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_value is empty"};
   }
 
   this->value = _value;
@@ -332,7 +332,7 @@ void ls::std::io::XmlNode::_checkIfAttributeReferenceIsValid(const ::std::shared
 {
   if (_attribute == nullptr)
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_attribute is null"};
   }
 }
 
@@ -340,7 +340,7 @@ void ls::std::io::XmlNode::_checkIfNameIsNotEmpty(const ::std::string &_name)
 {
   if (_name.empty())
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_name is empty"};
   }
 }
 
@@ -348,7 +348,7 @@ void ls::std::io::XmlNode::_checkIfNodeReferenceIsValid(const ::std::shared_ptr<
 {
   if (_child == nullptr)
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_child is null"};
   }
 }
 
@@ -370,7 +370,7 @@ bool ls::std::io::XmlNode::_hasAttribute(const ::std::string &_name)
 
   if (_name.empty())
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_name is empty"};
   }
   else
   {
@@ -399,7 +399,7 @@ bool ls::std::io::XmlNode::_hasChild(const ::std::string &_name)
 
   if (_name.empty())
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_name is empty"};
   }
   else
   {

+ 2 - 2
source/ls-std/io/xml/XmlParseParameter.cpp

@@ -3,7 +3,7 @@
 * Company:         Lynar Studios
 * E-Mail:          webmaster@lynarstudios.com
 * Created:         2023-02-05
-* Changed:         2023-02-05
+* Changed:         2023-02-07
 *
 * */
 
@@ -38,7 +38,7 @@ void ls::std::io::XmlParseParameter::_setNode(const ::std::shared_ptr<ls::std::i
 {
   if (_node == nullptr)
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_node is null"};
   }
 
   this->node = _node;

+ 2 - 2
source/ls-std/io/xml/XmlParser.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-11-26
- * Changed:         2023-02-05
+ * Changed:         2023-02-07
  *
  * */
 
@@ -57,7 +57,7 @@ void ls::std::io::XmlParser::_assignDocument(const ::std::shared_ptr<ls::std::io
 {
   if (_document == nullptr)
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_document is null"};
   }
 
   this->document = _document;

+ 3 - 3
source/ls-std/io/xml/XmlReader.cpp

@@ -3,7 +3,7 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-10-10
- * Changed:         2023-02-04
+ * Changed:         2023-02-07
  *
  * */
 
@@ -47,7 +47,7 @@ void ls::std::io::XmlReader::_assignDocument(const ::std::shared_ptr<ls::std::io
 {
   if (_document == nullptr)
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"_document is null"};
   }
 
   this->document = _document;
@@ -57,7 +57,7 @@ void ls::std::io::XmlReader::_assignFile(ls::std::io::File _xmlFile)
 {
   if (!_xmlFile.exists())
   {
-    throw ls::std::core::IllegalArgumentException{};
+    throw ls::std::core::IllegalArgumentException{"file does not exist: " + _xmlFile.getAbsoluteFilePath()};
   }
 
   this->xmlFile = _xmlFile;