Commit 6d946954 authored by Lukas Tietze's avatar Lukas Tietze

Exception-Basis-Klasse

parent d0df1e43
#pragma once
#include <exception>
#include "Util/ExeptionBase.hpp"
#include <string>
namespace lib
{
/**
* @brief Stellt eine Ausnahme beim Initialisieren des Vulkan-Kerns dar.
* Wird primär genutzt um Ausnahmen in Folge von gescheiterten vkCreateXYZ-Aufrufen von anderen exceptions
* zu unterscheiden, die nichts mit Vulkan zu tun haben.
*/
class CoreInitException final : public std::exception
{
public:
CoreInitException(const std::string &msg);
};
/**
* @brief Stellt eine Ausnahme beim Initialisieren des Vulkan-Kerns dar.
* Wird primär genutzt um Ausnahmen in Folge von gescheiterten vkCreateXYZ-Aufrufen von anderen exceptions
* zu unterscheiden, die nichts mit Vulkan zu tun haben.
*/
class CoreInitException final : public lib::ExceptionBase
{
public:
CoreInitException(const std::string &msg);
CoreInitException(const char *msg);
};
} // namespace lib
#pragma once
#include <string>
#include <exception>
#include "Util/ExeptionBase.hpp"
namespace lib
{
/**
* @brief Exception die beim Laden eines Modells auftreten kann.
*/
class ModelLoadException : public std::exception
class ModelLoadException : public lib::ExceptionBase
{
public:
ModelLoadException(const std::string &reason, const std::string &path);
......
#pragma once
#include <exception>
#include <string>
namespace lib
{
class ExceptionBase : public std::exception
{
private:
std::string message;
public:
ExceptionBase(std::string message);
ExceptionBase(const char *message);
const char *what() const noexcept override;
};
} // namespace lib
#pragma once
#include "Util/ExeptionBase.hpp"
#include <GlfwAndVulkan.hpp>
namespace lib
{
class OutOfMemoryException final : public lib::ExceptionBase
{
public:
OutOfMemoryException(vk::DeviceSize requested, vk::DeviceSize available, vk::DeviceSize available);
};
} // namespace lib
#include "Core/CoreInitException.hpp"
lib::CoreInitException::CoreInitException(const std::string &msg) : std::exception(msg.c_str())
lib::CoreInitException::CoreInitException(const std::string &msg) : lib::ExceptionBase(msg)
{
}
lib::CoreInitException::CoreInitException(const char *msg) : lib::ExceptionBase(msg)
{
}
\ No newline at end of file
#include "Core/Model/ModelLoadException.hpp"
#include "Util/Utils.hpp"
namespace
{
std::string MakeMessage(const std::string &reason, const std::string &path)
{
return lib::Format("Failed to load model from %! Reason: %", path, reason);
}
} // namespace
lib::ModelLoadException::ModelLoadException(const std::string &reason, const std::string &path)
: std::exception(MakeMessage(reason, path).c_str())
: lib::ExceptionBase(lib::Format("Failed to load model from %! Reason: %", path, reason))
{
}
\ No newline at end of file
#include "Util/ExeptionBase.hpp"
lib::ExceptionBase::ExceptionBase(std::string message)
: std::exception(),
message(message)
{
}
lib::ExceptionBase::ExceptionBase(const char *message)
: std::exception(message),
message()
{
}
const char *lib::ExceptionBase::what() const noexcept
{
return this->message.empty() ? this->std::exception::what() : this->message.c_str();
}
\ No newline at end of file
#include "VkUtil/Memory/OutOfMemoryException.hpp"
#include "Util/Utils.hpp"
lib::OutOfMemoryException::OutOfMemoryException(vk::DeviceSize requested, vk::DeviceSize available, vk::DeviceSize total)
: lib::ExceptionBase(lib::Format(
"Requested allocation of %b on memoryblock of %b with only %b free!", requested, total, available))
{
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment