Added more error macro variants.

This commit is contained in:
Relintai 2022-02-04 10:38:18 +01:00
parent e946184d2c
commit d8e06e36f0
3 changed files with 37 additions and 0 deletions

View File

@ -31,6 +31,10 @@
#define RLOG_ERR(str) \
Logger::log_error(str);
#define ERR_FAIL_MSG(msg) \
Logger::_log_error(__FUNCTION__, __FILE__, __LINE__, msg); \
return;
#define ERR_FAIL_INDEX(index, size) \
if ((index < 0) || (index >= size)) {\
Logger::_log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, ""); \
@ -38,6 +42,13 @@
} else\
((void)0)\
#define ERR_FAIL_INDEX_MSG(index, size, msg) \
if ((index < 0) || (index >= size)) {\
Logger::_log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, msg); \
return;\
} else\
((void)0)\
#define ERR_FAIL_INDEX_V(index, size, val) \
if ((index < 0) || (index >= size)) {\
Logger::_log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, ""); \
@ -45,6 +56,13 @@
} else\
((void)0)\
#define ERR_FAIL_INDEX_V_MSG(index, size, val, msg) \
if ((index < 0) || (index >= size)) {\
Logger::_log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, msg); \
return val;\
} else\
((void)0)\
#define ERR_FAIL_COND(cond) \
if (cond) {\
Logger::_log_error(__FUNCTION__, __FILE__, __LINE__, "ERR_FAIL_COND: \"" #cond "\" is true!"); \
@ -52,6 +70,13 @@
} else\
((void)0)\
#define ERR_FAIL_COND_MSG(cond, msg) \
if (cond) {\
Logger::_log_error(__FUNCTION__, __FILE__, __LINE__, msg); \
return;\
} else\
((void)0)\
#define ERR_FAIL_COND_V(cond, val) \
if (cond) {\
Logger::_log_error(__FUNCTION__, __FILE__, __LINE__, "ERR_FAIL_COND: \"" #cond "\" is true!"); \
@ -59,6 +84,13 @@
} else\
((void)0)\
#define ERR_FAIL_COND_V_MSG(cond, val, msg) \
if (cond) {\
Logger::_log_error(__FUNCTION__, __FILE__, __LINE__, msg); \
return val;\
} else\
((void)0)\
#define CRASH_INDEX(index, size) \
if ((index < 0) || (index >= size)) {\
Logger::_log_index_error(__FUNCTION__, __FILE__, __LINE__, index, size, "CRASH!"); \

View File

@ -44,6 +44,10 @@ void Logger::_log_error(const char *p_function, const char *p_file, int p_line,
{
printf("!ERROR: (%s) %s:%d. %s\n", p_file, p_function, p_line, str);
}
void Logger::_log_error(const char *p_function, const char *p_file, int p_line, const String &str)
{
printf("!ERROR: (%s) %s:%d. %s\n", p_file, p_function, p_line, str.c_str());
}
void Logger::_log_msg_error(const char *p_function, const char *p_file, int p_line, const char *p_msg, const char *str)
{
printf("!ERROR: (%s) %s:%d :: %s. %s\n", p_file, p_function, p_line, str, p_msg);

View File

@ -18,6 +18,7 @@ public:
static void log_error(const char *str);
static void _log_error(const char *p_function, const char *p_file, int p_line, const char *str);
static void _log_error(const char *p_function, const char *p_file, int p_line, const String &str);
static void _log_msg_error(const char *p_function, const char *p_file, int p_line, const char *p_msg, const char *str);
static void _log_index_error(const char *p_function, const char *p_file, int p_line, const int index, const int size, const char *str);
};