LeviLamina
Loading...
Searching...
No Matches
ErrorUtils.h
1#pragma once
2
3#include <system_error>
4#include <typeinfo>
5
6#include "ll/api/base/CompilerPredefine.h"
7#include "ll/api/base/Macro.h"
8#include "ll/api/base/StdInt.h"
9#include "ll/api/utils/StacktraceUtils.h"
10
11#include "ll/api/io/LogLevel.h"
12
13#include "mc/deps/core/utility/optional_ref.h"
14
15namespace ll::inline utils::error_utils {
16
18 void* impl;
19
20 LLAPI void* typeCast(std::type_info const&) const;
21
22public:
23 LLNDAPI AnyExceptionRef(std::exception_ptr const& ptr);
24 LLAPI ~AnyExceptionRef();
25
27 AnyExceptionRef(AnyExceptionRef const&) = delete;
28 AnyExceptionRef& operator=(AnyExceptionRef&&) = delete;
29 AnyExceptionRef& operator=(AnyExceptionRef const&) = delete;
30
31 template <class T>
32 [[nodiscard]] optional_ref<T> tryGet() const {
33 return reinterpret_cast<T*>(typeCast(typeid(T)));
34 }
35};
36
37LLNDAPI std::system_error getLastSystemError() noexcept;
38
39LLNDAPI std::exception_ptr createExceptionPtr(void*) noexcept;
40
41LLNDAPI Stacktrace stacktraceFromCurrentException(size_t skip = 0, size_t maxDepth = ~0ull);
42
43LLNDAPI std::string makeExceptionString(std::exception_ptr ePtr) noexcept;
44
45LLAPI void printCurrentException(
46 io::Logger& logger,
47 io::LogLevel level = io::LogLevel::Error,
48 std::exception_ptr const& = std::current_exception()
49) noexcept;
50
51template <class T>
52 requires(!std::is_same_v<T, std::exception_ptr>)
53inline void printException(T const& e, io::Logger& logger, io::LogLevel level = io::LogLevel::Error) noexcept {
54 printCurrentException(logger, level, std::make_exception_ptr(e));
55}
56} // namespace ll::inline utils::error_utils
Definition optional_ref.h:10
Definition ErrorUtils.h:17
STL namespace.