Lib
QOLを高める
exceptions.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdexcept>
4 #include <memory>
5 #include <windows.h>
6 
7 namespace yappy {
9 namespace error {
10 
15 std::string createStackTraceMsg(const std::string &msg);
16 
29 template <class E, class... Args>
30 __declspec(noreturn)
31 inline void throwTrace(const std::string &msg, Args&&... args)
32 {
33  throw E(createStackTraceMsg(msg), std::forward<Args>(args)...);
34 }
35 
36 
37 class FrameworkError : public std::runtime_error {
38 public:
39  FrameworkError(const std::string &msg) : runtime_error(msg) {}
40 };
41 
42 class Win32Error : public std::runtime_error {
43 public:
44  Win32Error(const std::string &msg, DWORD code);
45  const char *what() const override;
46 private:
47  std::string m_what;
48 };
49 
50 inline void checkWin32Result(bool cond, const std::string &msg)
51 {
52  if (!cond) {
53  throwTrace<Win32Error>(msg, ::GetLastError());
54  }
55 }
56 
57 class WinSockError : public Win32Error {
58 public:
59  WinSockError(const std::string &msg, int code) :
60  Win32Error(msg, static_cast<DWORD>(code))
61  {}
62 };
63 
64 
65 class MmioError : public std::runtime_error {
66 public:
67  MmioError(const std::string &msg, UINT code);
68  const char *what() const override;
69 private:
70  std::string m_what;
71 };
72 
73 class OggVorbisError : public std::runtime_error {
74 public:
75  OggVorbisError(const std::string &msg, int code);
76  const char *what() const override;
77 private:
78  std::string m_what;
79 };
80 
81 
82 template <class T>
83 inline void checkDXResult(HRESULT hr, const std::string &msg)
84 {
85  static_assert(std::is_base_of<DXError, T>::value, "T must inherit DXError");
86  if (FAILED(hr)) {
87  throwTrace<T>(msg, hr);
88  }
89 }
90 
91 class DXError : public std::runtime_error {
92 public:
93  DXError(const std::string &msg, HRESULT hr);
94  const char *what() const override;
95 private:
96  std::string m_what;
97 };
98 
99 class D3DError : public DXError {
100 public:
101  D3DError(const std::string &msg, HRESULT hr) :
102  DXError(msg, hr)
103  {}
104 };
105 
106 class DIError : public DXError {
107 public:
108  DIError(const std::string &msg, HRESULT hr) :
109  DXError(msg, hr)
110  {}
111 };
112 
113 class DSError : public DXError {
114 public:
115  DSError(const std::string &msg, HRESULT hr) :
116  DXError(msg, hr)
117  {}
118 };
119 
120 class XAudioError : public DXError {
121 public:
122  XAudioError(const std::string &msg, HRESULT hr) :
123  DXError(msg, hr)
124  {}
125 };
126 
127 } // namespace error
128 } // namespace yappy
STL namespace.
__declspec(noreturn) inline void throwTrace(const std
Throw exception with (msg + stacktrace) message.
Definition: exceptions.h:30
std::string createStackTraceMsg(const std::string &msg)
Returns (msg + stacktrace) string.
Definition: exceptions.cpp:11
Definition: config.cpp:6
void checkDXResult(HRESULT hr, const std::string &msg)
Definition: exceptions.h:83
FrameworkError(const std::string &msg)
Definition: exceptions.h:39
XAudioError(const std::string &msg, HRESULT hr)
Definition: exceptions.h:122
WinSockError(const std::string &msg, int code)
Definition: exceptions.h:59
char msg[LINE_DATA_SIZE-sizeof(LARGE_INTEGER)-sizeof(uint32_t)]
Definition: debug.cpp:159
void checkWin32Result(bool cond, const std::string &msg)
Definition: exceptions.h:50
DIError(const std::string &msg, HRESULT hr)
Definition: exceptions.h:108
DSError(const std::string &msg, HRESULT hr)
Definition: exceptions.h:115
D3DError(const std::string &msg, HRESULT hr)
Definition: exceptions.h:101