IndexOutOfBoundsException.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-10
  6. * Changed: 2023-02-23
  7. *
  8. * */
  9. #include <ls-std/core/exception/ExceptionMessage.hpp>
  10. #include <ls-std/core/exception/IndexOutOfBoundsException.hpp>
  11. using ls::std::core::Exception;
  12. using ls::std::core::IndexOutOfBoundsException;
  13. using std::move;
  14. using std::string;
  15. IndexOutOfBoundsException::IndexOutOfBoundsException() : Exception("IndexOutOfBoundsException")
  16. {}
  17. IndexOutOfBoundsException::IndexOutOfBoundsException(string _message) : IndexOutOfBoundsException()
  18. {
  19. this->message = ::move(_message);
  20. }
  21. IndexOutOfBoundsException::~IndexOutOfBoundsException() noexcept = default;
  22. const char *IndexOutOfBoundsException::what() const noexcept
  23. {
  24. string concatenatedMessage = this->name + " thrown - ";
  25. if (this->message.empty())
  26. {
  27. concatenatedMessage = concatenatedMessage + "provided index is out of bounds!";
  28. }
  29. else
  30. {
  31. concatenatedMessage = concatenatedMessage + this->message;
  32. }
  33. return ExceptionMessage{concatenatedMessage}.toCharacterPointer();
  34. }