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 * Unreal itself discourages the usage of C++ exceptions and there are also couple of thoughts above IError why
23 * that's the case. However there are third-party libraries which may require their users to catch errors their functions
24 * may yield via exceptions. For this reason there's an IError wrapper around std::exception base class which however
25 * will not preserve the actual type of the cought exception. For that use TCppException template.
26 */
27 class MCRO_API FCppException : public IError
28 {
29 public:
30 FCppException(std::exception const& input);
31 virtual ~FCppException() = default;
32
33 virtual TSharedRef<SErrorDisplay> CreateErrorWidget() override;
34
35 /** Storage for the exception but as the base STL type. It's copied to this member */
36 std::exception BaseException;
37
38 protected:
39 virtual FStringView GetExceptionType() const;
40 virtual void SerializeMembers(YAML::Emitter& emitter, bool isRoot) const override;
41 };
42
43 /**
44 * Use this template for catching STL exceptions to preserve the exception type name.
45 * @tparam Exception Type of the encapsulated exception
46 */
47 template <CDerivedFrom<std::exception> Exception>
49 {
50 public:
51 TCppException(Exception const& input)
52 : FCppException(input)
53 , TypedException(input)
54 {}
55
56 /** Storage for the exception but preserving its actual type. It's copied to this member */
57 Exception TypedException;
58
59 protected:
60 virtual FStringView GetExceptionType() const override
61 {
63 }
64 };
65}
FCppException(std::exception const &input)
std::exception BaseException
virtual void SerializeMembers(YAML::Emitter &emitter, bool isRoot) const override
virtual ~FCppException()=default
virtual FStringView GetExceptionType() const
virtual TSharedRef< SErrorDisplay > CreateErrorWidget() override
virtual FStringView GetExceptionType() const override
TCppException(Exception const &input)
constexpr FStringView TTypeName
Definition TypeName.h:131