16#include "AUI/Reflect/AReflect.h"
17#include <AUI/Common/AVector.h>
18#include <AUI/Platform/AStacktrace.h>
19#include <AUI/Traits/strings.h>
28class API_AUI_CORE AException :
public std::exception {
33 AException(
AStacktrace stacktrace) : mStacktrace(std::move(stacktrace)) {}
35 AException(
const AString& message) : AException() { mMessage = message.
toStdString(); }
37 AException(
const AException& exception) =
default;
38 AException(AException&& exception)
noexcept =
default;
41 : mStacktrace(std::move(stacktrace)), mCausedBy(std::move(causedBy)) {
45 virtual AString getMessage()
const noexcept {
return mMessage ? mMessage->c_str() :
"<no message>"; }
47 ~AException()
noexcept override =
default;
49 const char* what()
const noexcept override {
51 mMessage = getMessage().toStdString();
52 return mMessage->c_str();
55 const AStacktrace& stacktrace()
const noexcept {
return mStacktrace; }
58 const std::exception_ptr& causedBy()
const noexcept {
64 std::exception_ptr mCausedBy;
67inline std::ostream& operator<<(std::ostream& o,
const AException& e)
noexcept {
68 o <<
"(" << AReflect::name(&e) <<
") " << e.getMessage() << std::endl << e.stacktrace();
72 std::rethrow_exception(e.causedBy());
75 }
catch (
const std::exception& e) {
78 o <<
"unknown exception";
Abstract AUI exception.
Definition AException.h:28
Utility wrapper implementing the stack-allocated (fast) optional idiom.
Definition AOptional.h:32
Stacktrace consisting of a collection of stack function frames.
Definition AStacktrace.h:28
static AStacktrace capture(unsigned skipFrames=0, unsigned maxFrames=128) noexcept
Creates stacktrace of the current thread.
Definition AStacktraceImpl.cpp:156
Represents a Unicode character string.
Definition AString.h:37
std::string toStdString() const noexcept
Definition AString.cpp:338