SHADE_Y3/SHADE_Engine/src/Tools/SHException.h

88 lines
3.4 KiB
C
Raw Normal View History

/****************************************************************************************
* \file SHException.h
* \author Diren D Bharwani, diren.dbharwani, 390002520
* \brief Interface for custom exception types of SHADE Engine.
*
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
* disclosure of this file or its contents without the prior written consent
* of DigiPen Institute of Technology is prohibited.
****************************************************************************************/
#pragma once
#include <exception>
#include <string>
#include <source_location>
#include <string_view>
#include <cassert>
#include <cstdlib>
// Project Headers
#include "Logger/SHLogger.h"
namespace SHADE
{
/*-----------------------------------------------------------------------------------*/
/* Concepts */
/*-----------------------------------------------------------------------------------*/
template <typename ExceptionType>
concept IsException = std::is_base_of_v<std::exception, ExceptionType>;
/*-----------------------------------------------------------------------------------*/
/* Type Definitions */
/*-----------------------------------------------------------------------------------*/
/**
* @brief Base exception type thrown by SHADE Engine.
*/
class SHException : public std::exception
{
public:
/*---------------------------------------------------------------------------------*/
/* Constructors & Destructor */
/*---------------------------------------------------------------------------------*/
SHException
(
std::string msg = "",
const std::source_location& src = std::source_location::current()
) noexcept;
/*---------------------------------------------------------------------------------*/
/* Function Members */
/*---------------------------------------------------------------------------------*/
const char* what() const noexcept override;
protected:
/*---------------------------------------------------------------------------------*/
/* Data Members */
/*---------------------------------------------------------------------------------*/
mutable std::string message;
/*---------------------------------------------------------------------------------*/
/* Function Members */
/*---------------------------------------------------------------------------------*/
std::string GetOriginString() const noexcept;
private:
/*---------------------------------------------------------------------------------*/
/* Data Members */
/*---------------------------------------------------------------------------------*/
const std::source_location& origin;
};
}
2022-09-27 16:24:08 +08:00
#ifdef _DEBUG
#define SHASSERT(cond, msg) \
if (!(cond)) \
{ \
SHLOGV_CRITICAL(msg) \
std::abort(); \
}
#else
#define SHASSERT(cond, msg) { }
#endif