libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
HResultException.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef _WIN32
4#include <stdexcept>
5#include <string>
6#include <cstdio>
7#include <windows.h>
8
9namespace Ship {
10
17class HResultException : public std::runtime_error {
18 public:
19 explicit HResultException(HRESULT hr) : std::runtime_error(FormatHResultMessage(hr)), mHResult(hr) {
20 }
21
22 HResultException(HRESULT hr, const std::string& context)
23 : std::runtime_error(context + " " + FormatHResultMessage(hr)), mHResult(hr) {
24 }
25
27 HRESULT GetHResult() const noexcept {
28 return mHResult;
29 }
30
31 private:
32 HRESULT mHResult;
33
34 static std::string FormatHResultMessage(HRESULT hr) {
35 char buf[64];
36 std::snprintf(buf, sizeof(buf), "HRESULT failure: 0x%08X", static_cast<unsigned int>(hr));
37 return buf;
38 }
39};
40
41} // namespace Ship
42
43#endif
Exception type for failed Windows HRESULT values.
Definition HResultException.h:17
HResultException(HRESULT hr)
Definition HResultException.h:19
HResultException(HRESULT hr, const std::string &context)
Definition HResultException.h:22
HRESULT GetHResult() const noexcept
Returns the raw HRESULT value.
Definition HResultException.h:27
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14