MCRO
C++23 utilities for Unreal Engine.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
Error.h File Reference
#include "CoreMinimal.h"
#include "Mcro/Error.Fwd.h"
#include "Void.h"
#include "Mcro/Types.h"
#include "Mcro/Concepts.h"
#include "Mcro/SharedObjects.h"
#include "Mcro/Observable.Fwd.h"
#include "Mcro/TextMacros.h"
#include "Mcro/Text.h"
#include "Mcro/Delegates/EventDelegate.h"
#include "Mcro/LibraryIncludes/Start.h"
#include "yaml-cpp/yaml.h"
#include "Mcro/LibraryIncludes/End.h"
#include <source_location>

Go to the source code of this file.

Data Structures

class  Mcro::Error::IError
 A base class for a structured error handling and reporting with modular architecture and fluent API. More...
 
class  Mcro::Error::FAssertion
 A simple error type for checking booleans. It adds no extra features to IError. More...
 
class  Mcro::Error::FUnavailable
 A simple error type denoting that whatever is being accessed is not available like attempting to access nullptr. It adds no extra features to IError. More...
 
struct  Mcro::Error::TMaybe< T >
 A TValueOrError alternative for IError which allows implicit conversion from values and errors (no need for MakeError or MakeValue) and is boolean testable. It also doesn't have ambiguous state such as TValueOrError has, so a TMaybe will always have either an error or a value, it will never have neither of them or both of them. More...
 

Namespaces

namespace  Mcro
 
namespace  Mcro::Error
 Contains utilities for structured error handling.
 

Macros

#define ERROR_LOG(categoryName, verbosity, error)
 
#define ERROR_CLOG(condition, categoryName, verbosity, error)
 
#define ASSERT_RETURN(condition)
 Similar to check() macro, but return an error instead of crashing.
 
#define UNAVAILABLE()
 Denote that a resource which is asked for doesn't exist.
 
#define MCRO_PROPAGATE_FAIL_3(type, var, expression)
 
#define MCRO_PROPAGATE_FAIL_2(var, expression)
 
#define MCRO_PROPAGATE_FAIL_1(expression)
 
#define PROPAGATE_FAIL(...)
 If a function returns a TMaybe or an FCanFail inside another function which may also return another error use this convenience macro to propagate the failure.
 

Typedefs

using Mcro::Error::FCanFail = TMaybe<FVoid>
 Indicate that an otherwise void function that it may fail with an IError.
 
using Mcro::Error::FTrueOrReason = TMaybe<FVoid>
 Syntactically same as FCanFail but for functions which is explicitly used to query some boolean decidable thing, and which can also provide a reason why the queried thing is false.
 

Functions

FORCEINLINE FCanFail Mcro::Error::Success ()
 Return an FCanFail or FTrueOrReason indicating a success or truthy output.
 

Detailed Description

Author
David Mórász
Date
2025

Definition in file Error.h.

Macro Definition Documentation

◆ ASSERT_RETURN

#define ASSERT_RETURN ( condition)
Value:
if (UNLIKELY(!(condition))) \
->WithLocation() \
->AsRecoverable() \
->WithCodeContext(PREPROCESSOR_TO_TEXT(condition))
#define PREPROCESSOR_TO_TEXT(x)
Definition Macros.h:18
A simple error type for checking booleans. It adds no extra features to IError.
Definition Error.h:542
static TSharedRef< T > Make(T *newError, Args &&... args)
To ensure automatic type reflection use IError::Make instead of manually constructing error objects.
Definition Error.h:144

Similar to check() macro, but return an error instead of crashing.

Definition at line 660 of file Error.h.

◆ ERROR_CLOG

#define ERROR_CLOG ( condition,
categoryName,
verbosity,
error )
Value:
UE_CLOG(condition, categoryName, verbosity, TEXT_"%s", *((error) \
->WithLocation() \
->Report() \
->ToString() \
))
#define TEXT_
A convenience alternative to Unreal's own TEXT macro but this one doesn't require parenthesis around ...
Definition TextMacros.h:51

Definition at line 652 of file Error.h.

◆ ERROR_LOG

#define ERROR_LOG ( categoryName,
verbosity,
error )
Value:
UE_LOG(categoryName, verbosity, TEXT_"%s", *((error) \
->WithLocation() \
->Report() \
->ToString() \
))

Definition at line 645 of file Error.h.

◆ MCRO_PROPAGATE_FAIL_1

#define MCRO_PROPAGATE_FAIL_1 ( expression)
Value:
MCRO_PROPAGATE_FAIL_2(PREPROCESSOR_JOIN(tempResult, __LINE__), expression)
#define MCRO_PROPAGATE_FAIL_2(var, expression)
Definition Error.h:678

Definition at line 679 of file Error.h.

◆ MCRO_PROPAGATE_FAIL_2

#define MCRO_PROPAGATE_FAIL_2 ( var,
expression )
Value:
MCRO_PROPAGATE_FAIL_3(auto, var, expression)
#define MCRO_PROPAGATE_FAIL_3(type, var, expression)
Definition Error.h:673

Definition at line 678 of file Error.h.

◆ MCRO_PROPAGATE_FAIL_3

#define MCRO_PROPAGATE_FAIL_3 ( type,
var,
expression )
Value:
type var = (expression); \
if (UNLIKELY(var.HasError())) return var.GetError() \
->WithLocation()

Definition at line 673 of file Error.h.

◆ PROPAGATE_FAIL

#define PROPAGATE_FAIL ( ...)
Value:
MACRO_OVERLOAD(MCRO_PROPAGATE_FAIL_, __VA_ARGS__)
#define MACRO_OVERLOAD(prefix,...)
Implement preprocessor function overloading based on argument count for a set of macros following a d...
Definition Macros.h:38

If a function returns a TMaybe or an FCanFail inside another function which may also return another error use this convenience macro to propagate the failure.

The following overloads are available:

  • (expression) Use this when the value of success is not needed further below. This will create a local variable with an automatically determined name and type
  • (var, expression) Use this when the value of success will be used further below. The local variable will be created with auto
  • (type, var, expression) Use this when the value of success will be used further below and its local variable should have an explicit type

Definition at line 694 of file Error.h.

◆ UNAVAILABLE

#define UNAVAILABLE ( )
Value:
->WithLocation() \
->AsRecoverable()
A simple error type denoting that whatever is being accessed is not available like attempting to acce...
Definition Error.h:550

Denote that a resource which is asked for doesn't exist.

Definition at line 668 of file Error.h.