sculpto
throw_if_failed.h
Go to the documentation of this file.
1/*!****************************************************************//*!*
2 * \file throw_if_failed.h
3 * \brief Helper throw if failed inline function implementation function.
4 * Commonly used in DirectX module.
5 *
6 * \author Sabitov Kirill
7 * \date 22 June 2022
8 *********************************************************************/
9
10#pragma once
11
12#include "sclpch.h"
13
14namespace scl::dx
15{
17 class com_exeption: public std::exception
18 {
19 private:
21 HRESULT Result;
22
23 public:
25 com_exeption(HRESULT hr) :Result(hr) {}
26
27 const char *what() const override
28 {
29 static char str[64] {};
30 sprintf_s(str, "Failure with HRESULT of %08X",
31 static_cast<unsigned int>(Result));
32 return str;
33 }
34 };
35
36 /*!*
37 * Helper utility converts D3D API failures into exceptions.
38 *
39 * \param hr COM result handle.
40 * \return None.
41 */
42 inline void ThrowIfFailed(HRESULT hr)
43 {
44 if (FAILED(hr))
45 {
46 throw com_exeption(hr);
47 }
48 }
49}
const char * what() const override
void ThrowIfFailed(HRESULT hr)
Sculpto library prehompiled header. Defines common definitions, includes commonly used modules.