Diligent Engine API Reference: D:/GitHub/DiligentEngine/DiligentCore/Graphics/GraphicsEngineD3DBase/include/D3DErrors.h Source File

Diligent Engine API Reference

D3DErrors.h
1 /* Copyright 2015-2018 Egor Yusov
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
12 *
13 * In no event and under no legal theory, whether in tort (including negligence),
14 * contract, or otherwise, unless required by applicable law (such as deliberate
15 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
16 * liable for any damages, including any direct, indirect, special, incidental,
17 * or consequential damages of any character arising as a result of this License or
18 * out of the use or inability to use the software (including but not limited to damages
19 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
20 * all other commercial damages or losses), even if such Contributor has been advised
21 * of the possibility of such damages.
22 */
23
24 #pragma once
25
26 #include "Errors.h"
27
30
31 namespace Diligent
32 {
33
35 class ComErrorDesc
36 {
37 public:
38 ComErrorDesc( HRESULT hr )
39 {
40 FormatMessageA(
41 FORMAT_MESSAGE_FROM_SYSTEM |
42 FORMAT_MESSAGE_IGNORE_INSERTS,
43 NULL,
44 hr,
45 MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ),
46 m_Msg,
47 _countof(m_Msg),
48 NULL );
49 auto nLen = strlen( m_Msg );
50 if( nLen > 1 && m_Msg[nLen - 1] == '\n' )
51 {
52 m_Msg[nLen - 1] = 0;
53 if( m_Msg[nLen - 2] == '\r' )
54 {
55 m_Msg[nLen - 2] = 0;
56 }
57 }
58 }
59
60 const char* Get(){ return m_Msg; }
61
62 private:
63 char m_Msg[4096];
64 };
65
66 }
67
68
69 #define CHECK_D3D_RESULT_THROW(Expr, Message)\
70 { \
71 HRESULT _hr_ = Expr; \
72 if(FAILED(_hr_)) \
73 { \
74 ComErrorDesc ErrDesc( _hr_ ); \
75 LOG_ERROR_AND_THROW( Message, "\nHRESULT Desc: ", ErrDesc.Get());\
76 } \
77 }
78
79 #define CHECK_D3D_RESULT_THROW_EX(Expr, ...)\
80 { \
81 HRESULT _hr_ = Expr; \
82 if(FAILED(_hr_)) \
83 { \
84 Diligent::MsgStream ms; \
85 Diligent::FormatMsg(ms, __VA_ARGS__); \
86 ComErrorDesc ErrDesc( _hr_ ); \
87 LOG_ERROR_AND_THROW( ms.str(), "\nHRESULT Desc: ", ErrDesc.Get());\
88 } \
89 }
Diligent
Graphics engine namespace.
Definition: AdaptiveFixedBlockAllocator.h:30
Diligent::ComErrorDesc
Helper class that provides description of a COM error.
Definition: D3DErrors.h:35