From fef3fe41960a564aee1c02509cf73d8961adf3bd Mon Sep 17 00:00:00 2001 From: assiduous Date: Fri, 24 Jan 2020 15:05:34 -0800 Subject: Updated handling of fatal errors --- Primitives/interface/Errors.h | 55 +++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 20 deletions(-) (limited to 'Primitives/interface') diff --git a/Primitives/interface/Errors.h b/Primitives/interface/Errors.h index 2e1c22d1..417fe87e 100644 --- a/Primitives/interface/Errors.h +++ b/Primitives/interface/Errors.h @@ -49,7 +49,7 @@ inline void ThrowIf(std::string&& msg) } template -void LogError(const char* Function, const char* FullFilePath, int Line, const ArgsType&... Args) +void LogError(bool IsFatal, const char* Function, const char* FullFilePath, int Line, const ArgsType&... Args) { std::string FileName(FullFilePath); @@ -59,12 +59,12 @@ void LogError(const char* Function, const char* FullFilePath, int Line, const Ar auto Msg = FormatString(Args...); if (DebugMessageCallback != nullptr) { - DebugMessageCallback(bThrowException ? DebugMessageSeverity::FatalError : DebugMessageSeverity::Error, Msg.c_str(), Function, FileName.c_str(), Line); + DebugMessageCallback(IsFatal ? DebugMessageSeverity::FatalError : DebugMessageSeverity::Error, Msg.c_str(), Function, FileName.c_str(), Line); } else { // No callback set - output to cerr - std::cerr << "Diligent Engine: " << (bThrowException ? "Fatal Error" : "Error") << " in " << Function << "() (" << FileName << ", " << Line << "): " << Msg << '\n'; + std::cerr << "Diligent Engine: " << (IsFatal ? "Fatal Error" : "Error") << " in " << Function << "() (" << FileName << ", " << Line << "): " << Msg << '\n'; } ThrowIf(std::move(Msg)); } @@ -73,13 +73,19 @@ void LogError(const char* Function, const char* FullFilePath, int Line, const Ar -#define LOG_ERROR(...) \ - do \ - { \ - Diligent::LogError(__FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \ +#define LOG_ERROR(...) \ + do \ + { \ + Diligent::LogError(/*IsFatal=*/false, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \ } while (false) +#define LOG_FATAL_ERROR(...) \ + do \ + { \ + Diligent::LogError(/*IsFatal=*/true, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \ + } while (false) + #define LOG_ERROR_ONCE(...) \ do \ { \ @@ -92,10 +98,16 @@ void LogError(const char* Function, const char* FullFilePath, int Line, const Ar } while (false) -#define LOG_ERROR_AND_THROW(...) \ - do \ - { \ - Diligent::LogError(__FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \ +#define LOG_ERROR_AND_THROW(...) \ + do \ + { \ + Diligent::LogError(/*IsFatal=*/false, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \ + } while (false) + +#define LOG_FATAL_ERROR_AND_THROW(...) \ + do \ + { \ + Diligent::LogError(/*IsFatal=*/true, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__); \ } while (false) @@ -106,9 +118,10 @@ void LogError(const char* Function, const char* FullFilePath, int Line, const Ar if (Diligent::DebugMessageCallback != nullptr) Diligent::DebugMessageCallback(Severity, _msg.c_str(), nullptr, nullptr, 0); \ } while (false) -#define LOG_ERROR_MESSAGE(...) LOG_DEBUG_MESSAGE(Diligent::DebugMessageSeverity::Error, ##__VA_ARGS__) -#define LOG_WARNING_MESSAGE(...) LOG_DEBUG_MESSAGE(Diligent::DebugMessageSeverity::Warning, ##__VA_ARGS__) -#define LOG_INFO_MESSAGE(...) LOG_DEBUG_MESSAGE(Diligent::DebugMessageSeverity::Info, ##__VA_ARGS__) +#define LOG_FATAL_ERROR_MESSAGE(...) LOG_DEBUG_MESSAGE(Diligent::DebugMessageSeverity::FatalError, ##__VA_ARGS__) +#define LOG_ERROR_MESSAGE(...) LOG_DEBUG_MESSAGE(Diligent::DebugMessageSeverity::Error, ##__VA_ARGS__) +#define LOG_WARNING_MESSAGE(...) LOG_DEBUG_MESSAGE(Diligent::DebugMessageSeverity::Warning, ##__VA_ARGS__) +#define LOG_INFO_MESSAGE(...) LOG_DEBUG_MESSAGE(Diligent::DebugMessageSeverity::Info, ##__VA_ARGS__) #define LOG_DEBUG_MESSAGE_ONCE(Severity, ...) \ @@ -122,9 +135,10 @@ void LogError(const char* Function, const char* FullFilePath, int Line, const Ar } \ } while (false) -#define LOG_ERROR_MESSAGE_ONCE(...) LOG_DEBUG_MESSAGE_ONCE(Diligent::DebugMessageSeverity::Error, ##__VA_ARGS__) -#define LOG_WARNING_MESSAGE_ONCE(...) LOG_DEBUG_MESSAGE_ONCE(Diligent::DebugMessageSeverity::Warning, ##__VA_ARGS__) -#define LOG_INFO_MESSAGE_ONCE(...) LOG_DEBUG_MESSAGE_ONCE(Diligent::DebugMessageSeverity::Info, ##__VA_ARGS__) +#define LOG_FATAL_ERROR_MESSAGE_ONCE(...) LOG_DEBUG_MESSAGE_ONCE(Diligent::DebugMessageSeverity::FatalError, ##__VA_ARGS__) +#define LOG_ERROR_MESSAGE_ONCE(...) LOG_DEBUG_MESSAGE_ONCE(Diligent::DebugMessageSeverity::Error, ##__VA_ARGS__) +#define LOG_WARNING_MESSAGE_ONCE(...) LOG_DEBUG_MESSAGE_ONCE(Diligent::DebugMessageSeverity::Warning, ##__VA_ARGS__) +#define LOG_INFO_MESSAGE_ONCE(...) LOG_DEBUG_MESSAGE_ONCE(Diligent::DebugMessageSeverity::Info, ##__VA_ARGS__) #define CHECK(Expr, Severity, ...) \ @@ -136,9 +150,10 @@ void LogError(const char* Function, const char* FullFilePath, int Line, const Ar } \ } while (false) -#define CHECK_ERR(Expr, ...) CHECK(Expr, Diligent::DebugMessageSeverity::Error, ##__VA_ARGS__) -#define CHECK_WARN(Expr, ...) CHECK(Expr, Diligent::DebugMessageSeverity::Warning, ##__VA_ARGS__) -#define CHECK_INFO(Expr, ...) CHECK(Expr, Diligent::DebugMessageSeverity::Info, ##__VA_ARGS__) +#define CHECK_FATAL_ERR(Expr, ...) CHECK(Expr, Diligent::DebugMessageSeverity::FatalError, ##__VA_ARGS__) +#define CHECK_ERR(Expr, ...) CHECK(Expr, Diligent::DebugMessageSeverity::Error, ##__VA_ARGS__) +#define CHECK_WARN(Expr, ...) CHECK(Expr, Diligent::DebugMessageSeverity::Warning, ##__VA_ARGS__) +#define CHECK_INFO(Expr, ...) CHECK(Expr, Diligent::DebugMessageSeverity::Info, ##__VA_ARGS__) #define CHECK_THROW(Expr, ...) \ do \ -- cgit v1.2.3