MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
HResultMacros.h
Go to the documentation of this file.
1
/** @noop License Comment
2
* @file
3
* @copyright
4
* This Source Code is subject to the terms of the Mozilla Public License, v2.0.
5
* If a copy of the MPL was not distributed with this file You can obtain one at
6
* https://mozilla.org/MPL/2.0/
7
*
8
* @author David Mórász
9
* @date 2025
10
*/
11
12
#pragma once
13
14
#include "CoreMinimal.h"
15
#include "
McroWindows/Error/WindowsError.h
"
16
17
/**
18
* @file
19
* This header provides convenience macros for dealing with API returning `HRESULT` elegantly
20
*/
21
22
#if UE_BUILD_SHIPPING
23
#define HR_WITH_STACKTRACE
24
#else
25
#define HR_WITH_STACKTRACE ->WithCppStackTrace()
26
#endif
27
28
#define MCRO_TRY_WITH_IMPL(tempVar, expression, noErrorInfo) \
29
HRESULT tempVar = (expression); \
30
if (UNLIKELY(tempVar != S_OK)) \
31
return Mcro::Error::IError::Make(new Mcro::Windows::Error::FHresultError(tempVar, noErrorInfo)) \
32
->WithLocation() \
33
->AsRecoverable \
34
->WithCodeContext(PREPROCESSOR_TO_TEXT(expression))
//
35
36
/** Use this macro in a function which returns an `Mcro::Error::TMaybe`. */
37
#define HR_TRY_WITH(expression, noErrorInfo) \
38
MCRO_TRY_WITH_IMPL(PREPROCESSOR_JOIN(tempHr, __LINE__), expression, noErrorInfo)
39
40
/**
41
* Use this macro in a function which returns an `Mcro::Error::TMaybe`. On non-shipping builds stacktrace is captured
42
* by default.
43
*/
44
#define HR_TRY(expression) \
45
HR_TRY_WITH(expression, false) \
46
HR_WITH_STACKTRACE \
47
->AsFatal() \
48
->BreakDebugger()
//
49
50
/** Use this macro in a function which returns an `Mcro::Error::TMaybe`. This version doesn't capture a stacktrace. */
51
#define HR_TRY_FAST(expression) HR_TRY_WITH(expression, false)
52
53
/**
54
* Use this macro in a function which returns an `Mcro::Error::TMaybe`. This version doesn't capture a stacktrace and
55
* it won't calculate human readable messages from the HRESULT the error code.
56
*/
57
#define HR_TRY_RAW(expression) HR_TRY_WITH(expression, true)
WindowsError.h
McroWindows_Origin
Public
McroWindows
Error
HResultMacros.h
Generated by
1.12.0