From b442c158b75ca127be53bfaaa22984287df3663e Mon Sep 17 00:00:00 2001 From: Danilo Date: Sat, 22 Jun 2024 10:11:31 -0300 Subject: [PATCH] Implementa Exception --- CMakeLists.txt | 1 + inc/xna/exception.hpp | 37 +++++++++++++++++++++++++++++++++++++ inc/xna/platform-dx/dx.hpp | 1 + inc/xna/xna.hpp | 1 + 4 files changed, 40 insertions(+) create mode 100644 inc/xna/exception.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f6c8884..e7a3d84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,7 @@ # and include sub-projects here. # cmake_minimum_required (VERSION 3.8) +set(CMAKE_CXX_STANDARD 20) # Enable Hot Reload for MSVC compilers if supported. if (POLICY CMP0141) diff --git a/inc/xna/exception.hpp b/inc/xna/exception.hpp new file mode 100644 index 0000000..fd29578 --- /dev/null +++ b/inc/xna/exception.hpp @@ -0,0 +1,37 @@ +#ifndef XNA_EXCEPTION_HPP +#define XNA_EXCEPTION_HPP + +#include +#include +#include + +namespace xna { + struct ExMessage { + inline static const std::string InitializeComponent = "Unable to initialize component"; + }; + + struct Exception { + static void Throw(std::string const& message, const std::source_location location = std::source_location::current()) { + std::string error; + error.append("Exception in: "); + +#if _DEBUG + error.append(location.file_name()); + error.append("("); + error.append(std::to_string(location.line())); + error.append(":"); + error.append(std::to_string(location.column())); + error.append(") "); +#endif + error.append("'"); + error.append(location.function_name()); + error.append("': "); + error.append(message); + error.append("\n"); + + throw std::runtime_error(error); + } + }; +} + +#endif \ No newline at end of file diff --git a/inc/xna/platform-dx/dx.hpp b/inc/xna/platform-dx/dx.hpp index 871ff04..cacad3c 100644 --- a/inc/xna/platform-dx/dx.hpp +++ b/inc/xna/platform-dx/dx.hpp @@ -59,6 +59,7 @@ using comptr = Microsoft::WRL::ComPtr; // OTHERS INCLUDES //--------------------------------// +#include "../exception.hpp" #include "../graphics/blendstate.hpp" #include "../graphics/adapter.hpp" #include "../graphics/device.hpp" diff --git a/inc/xna/xna.hpp b/inc/xna/xna.hpp index e2d56e8..b19b922 100644 --- a/inc/xna/xna.hpp +++ b/inc/xna/xna.hpp @@ -3,6 +3,7 @@ #include "types.hpp" #include "helpers.hpp" #include "enums.hpp" +#include "exception.hpp" #include "audio/audioengine.hpp" #include "audio/soundeffect.hpp" #include "common/color.hpp"