diff --git a/include/vkcv/FeatureManager.hpp b/include/vkcv/FeatureManager.hpp index 5ab424b2dcaaa88a738302fd17433643cebb9fd3..0ed0d440e144032ec69f84f12d742d82a6849b8b 100644 --- a/include/vkcv/FeatureManager.hpp +++ b/include/vkcv/FeatureManager.hpp @@ -421,7 +421,7 @@ namespace vkcv { if (!checkSupport(features, required)) { if (required) { - throw std::runtime_error("Required feature is not supported!"); + vkcv_log_throw_error("Required feature is not supported!"); } return false; diff --git a/include/vkcv/Logger.hpp b/include/vkcv/Logger.hpp index 9d4fa86f2b42e8190e7dc57c2ad897a76f945126..a1805651323f8c9200d16a6a7e999c82c3dc3c90 100644 --- a/include/vkcv/Logger.hpp +++ b/include/vkcv/Logger.hpp @@ -6,6 +6,7 @@ */ #include <cstdio> +#include <exception> namespace vkcv { @@ -113,4 +114,39 @@ namespace vkcv { #define vkcv_log(level, ...) {} #endif +/** + * @brief Macro-function to log the message of any error + * or an exception. + * + * @param[in] error Error or exception + */ +#define vkcv_log_error(error) { \ + vkcv_log(LogLevel::ERROR, "%s", (error).what()); \ +} + +/** + * @brief Macro-function to throw and log any error or + * an exception. + * + * @param[in] error Error or exception + */ +#define vkcv_log_throw(error) { \ + try { \ + throw error; \ + } catch (const std::exception& e) { \ + vkcv_log_error(e); \ + throw; \ + } \ +} + +/** + * @brief Macro-function to throw and log an error + * with its custom message. + * + * @param[in] message Error message + */ +#define vkcv_log_throw_error(message) { \ + vkcv_log_throw(std::runtime_error(message)); \ +} + } diff --git a/src/vkcv/Context.cpp b/src/vkcv/Context.cpp index f0520f0505b193e0e13d7f724242f1286f84634e..0f5a07c438914c91b5f093678920b8026086c91a 100644 --- a/src/vkcv/Context.cpp +++ b/src/vkcv/Context.cpp @@ -352,7 +352,7 @@ namespace vkcv }; if (!checkSupport(supportedLayers, validationLayers)) { - throw std::runtime_error("Validation layers requested but not available!"); + vkcv_log_throw_error("Validation layers requested but not available!"); } #endif @@ -377,7 +377,7 @@ namespace vkcv requiredExtensions.insert(requiredExtensions.end(), instanceExtensions.begin(), instanceExtensions.end()); if (!checkSupport(supportedExtensions, requiredExtensions)) { - throw std::runtime_error("The requested instance extensions are not supported!"); + vkcv_log_throw_error("The requested instance extensions are not supported!"); } const vk::ApplicationInfo applicationInfo( @@ -408,7 +408,7 @@ namespace vkcv vk::PhysicalDevice physicalDevice; if (!pickPhysicalDevice(instance, physicalDevice)) { - throw std::runtime_error("Picking suitable GPU as physical device failed!"); + vkcv_log_throw_error("Picking suitable GPU as physical device failed!"); } FeatureManager featureManager (physicalDevice); diff --git a/src/vkcv/FeatureManager.cpp b/src/vkcv/FeatureManager.cpp index 8c8c16a536ccf0259cca33c94ab3947b2b3c43c3..502b07971bf0e20a3f02d94506a55ab0dcfcd5cf 100644 --- a/src/vkcv/FeatureManager.cpp +++ b/src/vkcv/FeatureManager.cpp @@ -557,7 +557,7 @@ m_physicalDevice.getFeatures2(&query) delete[] clone; if (required) { - throw std::runtime_error("Required extension is not supported!"); + vkcv_log_throw_error("Required extension is not supported!"); } return false;