GameKit  0.0.1a
C++ gamedev tools
Exception.hpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: Exception.hpp
5  *
6  * Description:
7  *
8  * Created: 14/12/2014 05:02:53
9  *
10  * Author: Quentin Bazin, <quent42340@gmail.com>
11  *
12  * =====================================================================================
13  */
14 #ifndef GK_EXCEPTION_HPP_
15 #define GK_EXCEPTION_HPP_
16 
17 #include <exception>
18 #include <string>
19 
20 #include "gk/core/Debug.hpp"
21 
22 #define EXCEPTION(args...) (gk::Exception(__LINE__, _FILE, args))
23 
24 namespace gk {
25 
26 class Exception {
27  public:
28  template<typename... Args>
29  Exception(u16 line, std::string filename, Args... args) noexcept {
31  m_errorMsg += "at " + filename + ":" + std::to_string(line) + ": ";
32  m_errorMsg += Debug::makeString(std::forward<Args>(args)...);
34  }
35 
36  virtual const char *what() const noexcept {
37  return m_errorMsg.c_str();
38  }
39 
40  private:
41  std::string m_errorMsg;
42 };
43 
44 } // namespace gk
45 
46 #endif // GK_EXCEPTION_HPP_
std::string makeString(Args &&...args)
Definition: Debug.hpp:53
Exception(u16 line, std::string filename, Args... args) noexcept
Definition: Exception.hpp:29
std::string textColor(u8 color=TextColor::White, bool bold=false)
Definition: Debug.hpp:44
virtual const char * what() const noexcept
Definition: Exception.hpp:36
unsigned short u16
Definition: IntTypes.hpp:22
std::string m_errorMsg
Definition: Exception.hpp:41