diff --git a/include/inexor/vulkan-renderer/exception.hpp b/include/inexor/vulkan-renderer/exception.hpp index 2f09353f6..915441715 100644 --- a/include/inexor/vulkan-renderer/exception.hpp +++ b/include/inexor/vulkan-renderer/exception.hpp @@ -2,24 +2,29 @@ #include +#include #include #include namespace inexor::vulkan_renderer { -/// @brief A custom base class for exceptions +/// A custom base class for exceptions class InexorException : public std::runtime_error { public: - // No need to define own constructors. + // There is no need to define our own constructors using std::runtime_error::runtime_error; }; -/// @brief InexorException for Vulkan specific things. +/// Custom exception class for Vulkan related exceptions class VulkanException final : public InexorException { public: - /// @param message The exception message. - /// @param result The VkResult value of the Vulkan API call which failed. - VulkanException(std::string message, VkResult result); + /// Default constructor + /// Here we are using `C++20 source location feature `__ + /// @param message The exception message + /// @param result The VkResult value of the Vulkan API call which failed + /// @param location The source location + VulkanException(std::string message, VkResult result, + std::source_location location = std::source_location::current()); }; } // namespace inexor::vulkan_renderer diff --git a/src/vulkan-renderer/exception.cpp b/src/vulkan-renderer/exception.cpp index 6a5d3ea5c..c29dd0a35 100644 --- a/src/vulkan-renderer/exception.cpp +++ b/src/vulkan-renderer/exception.cpp @@ -4,11 +4,20 @@ namespace inexor::vulkan_renderer { -VulkanException::VulkanException(std::string message, const VkResult result) +VulkanException::VulkanException(std::string message, const VkResult result, const std::source_location location) : InexorException(message.append(" (") .append(vk_tools::as_string(result)) .append(": ") .append(vk_tools::result_to_description(result)) + .append(") (") + .append("file: ") + .append(location.file_name()) + .append(", line: ") + .append(std::to_string(location.line())) + .append(", column: ") + .append(std::to_string(location.column())) + .append(", function name: ") + .append(location.function_name()) .append(")")) {} } // namespace inexor::vulkan_renderer