-
Notifications
You must be signed in to change notification settings - Fork 41
Use C++20 source_location feature in exceptions #473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,24 +2,29 @@ | |||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
#include <vulkan/vulkan_core.h> | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
#include <source_location> | ||||||||||||||||||||||||||||
#include <stdexcept> | ||||||||||||||||||||||||||||
#include <string> | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
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 | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||
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 <https://en.cppreference.com/w/cpp/utility/source_location>`__ | ||||||||||||||||||||||||||||
/// @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()); | ||||||||||||||||||||||||||||
Comment on lines
+21
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I would not especially point out the new C++20 feature. |
||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
} // namespace inexor::vulkan_renderer |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()) | ||
Comment on lines
+7
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we are using C++20 we could use std::format here. |
||
.append(")")) {} | ||
|
||
} // namespace inexor::vulkan_renderer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.