1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
module;
#include <wrl.h>
#include <stdexcept>
export module dxcommon;
using Microsoft::WRL::ComPtr;
namespace dx {
export {
class exception : public std::exception
{
public:
exception() noexcept = default;
exception(HRESULT result, const char* file, int line) noexcept
{
sprintf_s(m_error, sizeof(m_error), "%s:%d Failed with HRESULT = %08X",
file, line, static_cast<unsigned int>(result));
}
exception(const char* error, const char* file, int line) noexcept
{
sprintf_s(m_error, sizeof(m_error), "%s:%d %s", file, line, error);
}
[[nodiscard]] const char* what() const noexcept final
{
return m_error;
}
private:
static thread_local char m_error[1024];
};
template <typename T>
void SafeRelease(ComPtr<T>& ptr)
{
if (ptr)
{
ptr->Release();
ptr = nullptr;
}
}
} // export
thread_local char exception::m_error[1024];
} // dx
|