MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
CppException.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 "Mcro/Error.h"
16
17#include <exception>
18
19namespace Mcro::Error
20{
21 /**
22 * @brief
23 * Unreal itself discourages the usage of C++ exceptions and there are also couple of thoughts above IError why
24 * that's the case. However, there are third-party libraries which may require their users to catch errors, their
25 * functions may, yield via exceptions. For this reason there's an IError wrapper around std::exception base class
26 * which however will not preserve the actual type of the caught exception. For that use TCppException template.
27 */
28 class MCRO_API FCppException : public IError
29 {
30 public:
31 FCppException(std::exception const& input);
32 virtual ~FCppException() = default;
33
34 virtual TSharedRef<SErrorDisplay> CreateErrorWidget() override;
35
36 /** Storage for the exception but as the base STL type. It's copied to this member */
37 std::exception BaseException;
38
39 protected:
40 virtual FStringView GetExceptionType() const;
41 virtual void SerializeMembers(YAML::Emitter& emitter) const override;
42 };
43
44 /**
45 * @brief Use this template for catching STL exceptions to preserve the exception type name.
46 * @tparam Exception Type of the encapsulated exception
47 */
48 template <CDerivedFrom<std::exception> Exception>
50 {
51 public:
52 TCppException(Exception const& input)
53 : FCppException(input)
54 , TypedException(input)
55 {}
56
57 /** @brief Storage for the exception but preserving its actual type. It's copied to this member */
58 Exception TypedException;
59
60 protected:
61 virtual FStringView GetExceptionType() const override
62 {
64 }
65 };
66}
Unreal itself discourages the usage of C++ exceptions and there are also couple of thoughts above IEr...
FCppException(std::exception const &input)
std::exception BaseException
virtual ~FCppException()=default
virtual FStringView GetExceptionType() const
virtual void SerializeMembers(YAML::Emitter &emitter) const override
Override this method if direct members should be serialized differently or extra members are added by...
virtual TSharedRef< SErrorDisplay > CreateErrorWidget() override
Override this function to customize how an error is displaxed for the end-user.
A base class for a structured error handling and reporting with modular architecture and fluent API.
Definition Error.h:68
Use this template for catching STL exceptions to preserve the exception type name.
virtual FStringView GetExceptionType() const override
Exception TypedException
Storage for the exception but preserving its actual type. It's copied to this member.
TCppException(Exception const &input)
Contains utilities for structured error handling.
Definition Error.Fwd.h:19
constexpr FStringView TTypeName
Get a friendly string of an input type without using typeid(T).name().
Definition TypeName.h:161