Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
RuntimeErrors.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Delegates/Delegate.h"
7#include "HAL/PlatformMisc.h"
8#include "Logging/LogVerbosity.h"
9#include "Misc/AssertionMacros.h"
10#include "Misc/Build.h"
11#include "Misc/CoreDelegates.h"
12
13class FText;
14
15// By default we bubble up runtime errors to the editor or log under the same circumstances as we assert with check/ensure
16#if !defined(UE_RAISE_RUNTIME_ERRORS)
17#define UE_RAISE_RUNTIME_ERRORS DO_CHECK
18#endif
19
21{
22 /**
23 * Prints out a runtime warning or error (typically by 'throwing' a BP script exception with the BP callstack)
24 *
25 * @param Verbosity The verbosity of the issue (should be Warning or Error)
26 * @param File File name ANSI string (__FILE__)
27 * @param Line Line number (__LINE__)
28 * @param Message Error or warning message to display, this may be surfaced to the user in the editor so make sure it is actionable (e.g., includes asset name or other useful info to help address the problem)
29 *
30 * @return false in all cases.
31 */
32 static void LogRuntimeIssue(ELogVerbosity::Type Verbosity, const ANSICHAR* FileName, int32 LineNumber, const FText& Message);
33
34 // The style of delegate called when a runtime issue occurs
35 DECLARE_DELEGATE_FourParams(FRuntimeErrorDelegate, ELogVerbosity::Type /*Verbosity*/, const ANSICHAR* /*File*/, int32 /*Line*/, const FText& /*Message*/);
36
37 // A delegate this is called when a runtime issue is raised
38 static FRuntimeErrorDelegate OnRuntimeIssueLogged;
39
40 /**
41 * Raises a runtime error and returns false.
42 *
43 * @param Expr Code expression ANSI string (#code)
44 * @param File File name ANSI string (__FILE__)
45 * @param Line Line number (__LINE__)
46 *
47 * @return false in all cases.
48 */
49 static bool LogRuntimeIssueReturningFalse(const ANSICHAR* Expr, const ANSICHAR* File, int32 Line);
50
51private:
53};
54
56 // Raises a runtime error to the log, possibly stopping in the BP debugger, but then returning execution to the caller
57 #define LogRuntimeError(Message) FRuntimeErrors::LogRuntimeIssue(ELogVerbosity::Error, __FILE__, __LINE__, Message)
58
59 // Raises a runtime warning to the log, possibly stopping in the BP debugger, but then returning execution to the caller
60 #define LogRuntimeWarning(Message) FRuntimeErrors::LogRuntimeIssue(ELogVerbosity::Warning, __FILE__, __LINE__, Message)
61
62 /**
63 * ensureAsRuntimeWarning() can be used to test for *non-fatal* errors at runtime.
64 *
65 * It is a lot like ensure() but it does not generate a C++ callstack or break in the C++ debugger.
66 *
67 * Rather than crashing or stopping in the C++ debugger, an error report with a script callstack will be printed to the output log.
68 * This is useful when you want runtime code verification but you're handling the error case anyway.
69 *
70 * Note: ensureAsRuntimeWarning() can be nested within conditionals!
71 *
72 * Example:
73 *
74 * if (ensureAsRuntimeWarning(InObject != nullptr))
75 * {
76 * InObject->Modify();
77 * }
78 *
79 * This code is safe to execute as the pointer dereference is wrapped in a non-nullptr conditional block, but
80 * you still want to find out if this ever happens so you can avoid side effects.
81 *
82 * ensureAsRuntimeWarning() resolves to just evaluate the expression when UE_RAISE_RUNTIME_ERRORS is 0 (typically shipping or test builds).
83 */
84 #define ensureAsRuntimeWarning(InExpression) (LIKELY(!!(InExpression)) || FRuntimeErrors::LogRuntimeIssueReturningFalse(#InExpression, __FILE__, __LINE__))
85#else
86 #define LogRuntimeError(Message)
87 #define LogRuntimeWarning(Message)
88 #define ensureAsRuntimeWarning(InExpression) (!!(InExpression))
89
90#endif
#define DO_CHECK
Definition Build.h:311
#define USING_CODE_ANALYSIS
#define DECLARE_DELEGATE_FourParams(DelegateName, Param1Type, Param2Type, Param3Type, Param4Type)
#define UE_RAISE_RUNTIME_ERRORS
Definition Text.h:357
static FRuntimeErrorDelegate OnRuntimeIssueLogged
static bool LogRuntimeIssueReturningFalse(const ANSICHAR *Expr, const ANSICHAR *File, int32 Line)
static void LogRuntimeIssue(ELogVerbosity::Type Verbosity, const ANSICHAR *FileName, int32 LineNumber, const FText &Message)