diff --git a/SDLU/CMakeLists.txt b/SDLU/CMakeLists.txt index ad6bc11..addb5bf 100644 --- a/SDLU/CMakeLists.txt +++ b/SDLU/CMakeLists.txt @@ -13,5 +13,6 @@ target_link_libraries(${PNAME} PRIVATE ${CMAKE_BINARY_DIR}/3rdparty/SDL/SDL2d.lib ) +add_subdirectory(exceptions) add_subdirectory(structures) add_subdirectory(graphics) \ No newline at end of file diff --git a/SDLU/exceptions/CMakeLists.txt b/SDLU/exceptions/CMakeLists.txt new file mode 100644 index 0000000..4e439d5 --- /dev/null +++ b/SDLU/exceptions/CMakeLists.txt @@ -0,0 +1,4 @@ +target_sources(${PNAME} PRIVATE + ${CMAKE_CURRENT_SORUCE_DIR}/Exceptions.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/ObjectCreationException.hpp +) \ No newline at end of file diff --git a/SDLU/exceptions/Exceptions.hpp b/SDLU/exceptions/Exceptions.hpp new file mode 100644 index 0000000..6add7a9 --- /dev/null +++ b/SDLU/exceptions/Exceptions.hpp @@ -0,0 +1,12 @@ +/** + * @file Exceptions.hpp + * @brief Provides utility and includes all exceptions + * @author Lauchmelder23 + * @date 16.05.2020 +*/ +#pragma once + +#include "ObjectCreationException.hpp" + +#define THROW_IF_NOT( condition, exception ) ( condition ? throw execption : false ) +#define THROW_IF( condition, exception ) ( condition ? false : throw execption ) \ No newline at end of file diff --git a/SDLU/exceptions/ObjectCreationException.hpp b/SDLU/exceptions/ObjectCreationException.hpp new file mode 100644 index 0000000..d409ba5 --- /dev/null +++ b/SDLU/exceptions/ObjectCreationException.hpp @@ -0,0 +1,30 @@ +/** + * @file ObjectCreationException.hpp + * @brief An exception object to handle failed object creations + * @author Lauchmelder23 + * @date 16.05.2020 + */ +#pragma once +#include + +namespace sdlu +{ + class ObjectCreationException : + virtual public std::exception + { + public: + ObjectCreationException(const char* description) : + m_pDescription(description) + { + // Empty + } + + virtual const char* what() const throw() + { + return m_pDescription; + } + + private: + const char* m_pDescription; + }; +} \ No newline at end of file