From 7471c09452b6ba93c6f20ef43b6e1a5559d3fdde Mon Sep 17 00:00:00 2001 From: Timerix Date: Thu, 1 Aug 2024 20:43:45 +0300 Subject: [PATCH] exceptions.hpp --- src/GUI/MainWindow.cpp | 2 +- src/GUI/exceptions.cpp | 12 ------------ src/exceptions.cpp | 19 +++++++++++++++++++ src/{GUI => }/exceptions.hpp | 13 +++++++++++-- 4 files changed, 31 insertions(+), 15 deletions(-) delete mode 100644 src/GUI/exceptions.cpp create mode 100644 src/exceptions.cpp rename src/{GUI => }/exceptions.hpp (51%) diff --git a/src/GUI/MainWindow.cpp b/src/GUI/MainWindow.cpp index fa97ac9..12ddf4a 100644 --- a/src/GUI/MainWindow.cpp +++ b/src/GUI/MainWindow.cpp @@ -2,7 +2,7 @@ #include #include #include "MainWindow.hpp" -#include "exceptions.hpp" +#include "../exceptions.hpp" #include "../format.hpp" #include "../Resources/fonts.hpp" diff --git a/src/GUI/exceptions.cpp b/src/GUI/exceptions.cpp deleted file mode 100644 index 4fc6156..0000000 --- a/src/GUI/exceptions.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "exceptions.hpp" -#include - -namespace ougge::GUI { - -SDLException_::SDLException_(const std::string& _file,const std::string& _func, int _line_n) - : UsefulException_(SDL_GetError(), _file, _func, _line_n) -{ - SDL_ClearError(); -} - -} diff --git a/src/exceptions.cpp b/src/exceptions.cpp new file mode 100644 index 0000000..3b8b3bf --- /dev/null +++ b/src/exceptions.cpp @@ -0,0 +1,19 @@ +#include "exceptions.hpp" +#include +#include + +namespace ougge { + +SDLException_::SDLException_(const std::string& _file,const std::string& _func, int _line_n) + : UsefulException_(std::string("SDLException: ") + SDL_GetError(), _file, _func, _line_n) +{ + SDL_ClearError(); +} + +IMGException_::IMGException_(const std::string& _file,const std::string& _func, int _line_n) + : UsefulException_(std::string("IMGException: ") + IMG_GetError(), _file, _func, _line_n) +{ + SDL_ClearError(); +} + +} diff --git a/src/GUI/exceptions.hpp b/src/exceptions.hpp similarity index 51% rename from src/GUI/exceptions.hpp rename to src/exceptions.hpp index 4b3b563..79d68ce 100644 --- a/src/GUI/exceptions.hpp +++ b/src/exceptions.hpp @@ -1,8 +1,8 @@ #pragma once -#include "../UsefulException.hpp" +#include "UsefulException.hpp" -namespace ougge::GUI { +namespace ougge { #define SDLException() SDLException_(__FILE__, __func__, __LINE__) @@ -11,6 +11,15 @@ public: SDLException_(const std::string& _file, const std::string& _func, int line_n); }; + +#define IMGException() IMGException_(__FILE__, __func__, __LINE__) + +class IMGException_ : public UsefulException_ { +public: + IMGException_(const std::string& _file, const std::string& _func, int line_n); +}; + + #define SDL_TRY(EXPR) if(EXPR) throw SDLException(); }