-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is very similar to lege::lua::Error(), and simplifies throwing errors originating from SDL code.
- Loading branch information
Showing
5 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <cstddef> | ||
|
||
#include <SDL_error.h> | ||
|
||
#include "sdl/error.hpp" | ||
|
||
namespace lege::sdl { | ||
|
||
Error::Error(std::string prefix) { | ||
const char *err = SDL_GetError(); | ||
m_msg = prefix; | ||
m_msg += ": "; | ||
m_msg += err; | ||
} | ||
|
||
Error::~Error() {} | ||
|
||
const char *Error::what() const noexcept { return m_msg.c_str(); } | ||
|
||
} // namespace lege::sdl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef LIBLEGE_sdl_ERROR_HPP | ||
#define LIBLEGE_sdl_ERROR_HPP | ||
|
||
#include <exception> | ||
#include <string> | ||
|
||
namespace lege::sdl { | ||
|
||
class Error : public std::exception { | ||
public: | ||
Error(std::string prefix = "sdl error"); | ||
virtual ~Error() override; | ||
|
||
virtual const char *what() const noexcept override; | ||
|
||
private: | ||
std::string m_msg; | ||
}; | ||
|
||
} // namespace lege::sdl | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef LIBLEGE_SDL_HELPERS_HPP | ||
#define LIBLEGE_SDL_HELPERS_HPP | ||
|
||
#include "sdl/error.hpp" | ||
|
||
#endif |