// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. #pragma once #include "Engine/Core/Log.h" #include "Engine/Core/Object.h" #include "Engine/Core/Types/String.h" namespace Log { class Logger; /// /// Represents errors that occur during application execution. /// class Exception : public Object { protected: String _message; String _additionalInfo; LogType _level; public: /// /// Creates default exception without additional data /// Exception() : Exception(String::Empty) { } /// /// Creates default exception with additional data /// /// Additional information that help describe error Exception(const String& additionalInfo) : Exception(TEXT("An exception has occurred."), additionalInfo) { } /// /// Creates new custom message with additional data /// /// The message that describes the error. /// Additional information that help describe error Exception(const String& message, const String& additionalInfo) : _message(message) , _additionalInfo(additionalInfo) , _level(LogType::Warning) { } public: /// /// Virtual destructor /// virtual ~Exception(); public: /// /// Gets a message that describes the current exception. /// /// Message string. FORCE_INLINE const String& GetMessage() const { return _message; } /// /// Gets a message that describes the current exception. /// /// Message string. FORCE_INLINE String GetMessage() { return _message; } /// /// Gets a additional info that describes the current exception details. /// /// Message string. FORCE_INLINE const String& GetAdditionalInfo() const { return _additionalInfo; } /// /// Gets a additional info that describes the current exception details. /// /// Message string. FORCE_INLINE String GetAdditionalInfo() { return _additionalInfo; } /// /// Get exception level /// /// Message Type used for display log FORCE_INLINE const LogType& GetLevel() const { return _level; } /// /// Get exception level /// /// Message Type used for display log FORCE_INLINE LogType GetLevel() { return _level; } /// /// Override exception level /// /// Override default value of exception level Exception& SetLevel(LogType level) { _level = level; return *this; } // TODO: implement StackTrace caching: https://www.codeproject.com/kb/threads/stackwalker.aspx public: // [Object] String ToString() const final override { if (!_additionalInfo.IsEmpty()) { return GetMessage() + TEXT(" \n\n Additional info: ") + GetAdditionalInfo(); } return GetMessage(); } }; }