Added ObjectCreationException and Utility Macros

This commit is contained in:
Robert 2020-05-16 15:55:18 +02:00
parent 740ddc2ca6
commit fac88781aa
4 changed files with 47 additions and 0 deletions

View file

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

View file

@ -0,0 +1,4 @@
target_sources(${PNAME} PRIVATE
${CMAKE_CURRENT_SORUCE_DIR}/Exceptions.hpp
${CMAKE_CURRENT_SOURCE_DIR}/ObjectCreationException.hpp
)

View file

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

View file

@ -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 <exception>
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;
};
}