mirror of
https://github.com/thunderbrewhq/squall.git
synced 2026-02-04 08:59:07 +00:00
feat(error): rework error macros
This commit is contained in:
parent
7c72c25553
commit
05f8a7eebf
4 changed files with 130 additions and 84 deletions
78
storm/error/Macros.hpp
Normal file
78
storm/error/Macros.hpp
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
#ifndef STORM_ERROR_MACROS_HPP
|
||||
#define STORM_ERROR_MACROS_HPP
|
||||
|
||||
// STORM_APP_FATAL
|
||||
#if !defined(NDEBUG) || defined(WHOA_ASSERTIONS_ENABLED)
|
||||
// Debug Build + Release Assertions Enabled Build
|
||||
#define STORM_APP_FATAL(...) \
|
||||
SErrPrepareAppFatal(__FILE__, __LINE__); \
|
||||
SErrDisplayAppFatal(__VA_ARGS__)
|
||||
#else
|
||||
// Release Build
|
||||
#define STORM_APP_FATAL(...) \
|
||||
SErrDisplayAppFatal(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
// STORM_ASSERT
|
||||
#if !defined(NDEBUG) || defined(WHOA_ASSERTIONS_ENABLED)
|
||||
// Debug Build + Release Assertions Enabled Build
|
||||
#define STORM_ASSERT(x) \
|
||||
if (!(x)) { \
|
||||
SErrDisplayError(STORM_ERROR_ASSERTION, __FILE__, __LINE__, #x, 0, 1, 0x11111111); \
|
||||
}
|
||||
#else
|
||||
// Release Build
|
||||
#define STORM_ASSERT(x)
|
||||
#endif
|
||||
|
||||
// STORM_VALIDATE_ASSERT
|
||||
#if !defined(NDEBUG)
|
||||
// Debug Build
|
||||
#define STORM_VALIDATE_ASSERT(x) \
|
||||
STORM_ASSERT(x)
|
||||
#elif defined(WHOA_ASSERTIONS_ENABLED)
|
||||
// Release Assertions Enabled Build
|
||||
#define STORM_VALIDATE_ASSERT(x) \
|
||||
if (!(x)) { \
|
||||
STORM_APP_FATAL(#x); \
|
||||
}
|
||||
#else
|
||||
// Release Build
|
||||
inline void NullAppFatal(const char* str) {};
|
||||
#define STORM_VALIDATE_ASSERT(x) \
|
||||
if (!(x)) { \
|
||||
NullAppFatal(#x); \
|
||||
}
|
||||
#endif
|
||||
|
||||
// STORM_VALIDATE
|
||||
#if !defined(NDEBUG)
|
||||
// Debug Build
|
||||
#define STORM_VALIDATE_BEGIN
|
||||
#define STORM_VALIDATE(x) \
|
||||
STORM_VALIDATE_ASSERT(x)
|
||||
#define STORM_VALIDATE_END
|
||||
#define STORM_VALIDATE_END_VOID
|
||||
#else
|
||||
// Release Build + Release Assertions Enabled Build
|
||||
#define STORM_VALIDATE_BEGIN \
|
||||
{ \
|
||||
bool __storm_result = true
|
||||
#define STORM_VALIDATE(x) \
|
||||
__storm_result &= !!(x); \
|
||||
STORM_VALIDATE_ASSERT(x)
|
||||
#define STORM_VALIDATE_END \
|
||||
if (!__storm_result) { \
|
||||
SErrSetLastError(ERROR_INVALID_PARAMETER); \
|
||||
return 0; \
|
||||
} \
|
||||
}
|
||||
#define STORM_VALIDATE_END_VOID \
|
||||
if (!__storm_result) { \
|
||||
SErrSetLastError(ERROR_INVALID_PARAMETER); \
|
||||
return; \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue