implement accompanying error macros that come with an error message, to replace ERR_EXPLAIN usage.
This commit is contained in:
parent
eb16c9830b
commit
8affda0916
1 changed files with 137 additions and 0 deletions
|
@ -140,6 +140,16 @@ extern bool _err_error_exists;
|
||||||
_err_error_exists = false; \
|
_err_error_exists = false; \
|
||||||
} while (0); // (*)
|
} while (0); // (*)
|
||||||
|
|
||||||
|
#define ERR_FAIL_INDEX_MSG(m_index, m_size, m_msg) \
|
||||||
|
do { \
|
||||||
|
if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
|
||||||
|
ERR_EXPLAIN(m_msg); \
|
||||||
|
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
|
||||||
|
return; \
|
||||||
|
} \
|
||||||
|
_err_error_exists = false; \
|
||||||
|
} while (0); // (*)
|
||||||
|
|
||||||
/** An index has failed if m_index<0 or m_index >=m_size, the function exits.
|
/** An index has failed if m_index<0 or m_index >=m_size, the function exits.
|
||||||
* This function returns an error value, if returning Error, please select the most
|
* This function returns an error value, if returning Error, please select the most
|
||||||
* appropriate error condition from error_macros.h
|
* appropriate error condition from error_macros.h
|
||||||
|
@ -154,6 +164,16 @@ extern bool _err_error_exists;
|
||||||
_err_error_exists = false; \
|
_err_error_exists = false; \
|
||||||
} while (0); // (*)
|
} while (0); // (*)
|
||||||
|
|
||||||
|
#define ERR_FAIL_INDEX_V_MSG(m_index, m_size, m_retval, m_msg) \
|
||||||
|
do { \
|
||||||
|
if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
|
||||||
|
ERR_EXPLAIN(m_msg); \
|
||||||
|
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
|
||||||
|
return m_retval; \
|
||||||
|
} \
|
||||||
|
_err_error_exists = false; \
|
||||||
|
} while (0); // (*)
|
||||||
|
|
||||||
/** An index has failed if m_index >=m_size, the function exits.
|
/** An index has failed if m_index >=m_size, the function exits.
|
||||||
* This function returns an error value, if returning Error, please select the most
|
* This function returns an error value, if returning Error, please select the most
|
||||||
* appropriate error condition from error_macros.h
|
* appropriate error condition from error_macros.h
|
||||||
|
@ -168,6 +188,16 @@ extern bool _err_error_exists;
|
||||||
_err_error_exists = false; \
|
_err_error_exists = false; \
|
||||||
} while (0); // (*)
|
} while (0); // (*)
|
||||||
|
|
||||||
|
#define ERR_FAIL_UNSIGNED_INDEX_V_MSG(m_index, m_size, m_retval, m_msg) \
|
||||||
|
do { \
|
||||||
|
if (unlikely((m_index) >= (m_size))) { \
|
||||||
|
ERR_EXPLAIN(m_msg); \
|
||||||
|
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
|
||||||
|
return m_retval; \
|
||||||
|
} \
|
||||||
|
_err_error_exists = false; \
|
||||||
|
} while (0); // (*)
|
||||||
|
|
||||||
/** Use this one if there is no sensible fallback, that is, the error is unrecoverable.
|
/** Use this one if there is no sensible fallback, that is, the error is unrecoverable.
|
||||||
* We'll return a null reference and try to keep running.
|
* We'll return a null reference and try to keep running.
|
||||||
*/
|
*/
|
||||||
|
@ -179,6 +209,15 @@ extern bool _err_error_exists;
|
||||||
} \
|
} \
|
||||||
} while (0); // (*)
|
} while (0); // (*)
|
||||||
|
|
||||||
|
#define CRASH_BAD_INDEX_MSG(m_index, m_size, m_msg) \
|
||||||
|
do { \
|
||||||
|
if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
|
||||||
|
ERR_EXPLAIN(m_msg); \
|
||||||
|
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), true); \
|
||||||
|
GENERATE_TRAP \
|
||||||
|
} \
|
||||||
|
} while (0); // (*)
|
||||||
|
|
||||||
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
||||||
* the function will exit.
|
* the function will exit.
|
||||||
*/
|
*/
|
||||||
|
@ -192,6 +231,16 @@ extern bool _err_error_exists;
|
||||||
_err_error_exists = false; \
|
_err_error_exists = false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ERR_FAIL_NULL_MSG(m_param, m_msg) \
|
||||||
|
{ \
|
||||||
|
if (unlikely(!m_param)) { \
|
||||||
|
ERR_EXPLAIN(m_msg); \
|
||||||
|
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter ' " _STR(m_param) " ' is null."); \
|
||||||
|
return; \
|
||||||
|
} \
|
||||||
|
_err_error_exists = false; \
|
||||||
|
}
|
||||||
|
|
||||||
#define ERR_FAIL_NULL_V(m_param, m_retval) \
|
#define ERR_FAIL_NULL_V(m_param, m_retval) \
|
||||||
{ \
|
{ \
|
||||||
if (unlikely(!m_param)) { \
|
if (unlikely(!m_param)) { \
|
||||||
|
@ -201,6 +250,16 @@ extern bool _err_error_exists;
|
||||||
_err_error_exists = false; \
|
_err_error_exists = false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ERR_FAIL_NULL_V_MSG(m_param, m_retval, m_msg) \
|
||||||
|
{ \
|
||||||
|
if (unlikely(!m_param)) { \
|
||||||
|
ERR_EXPLAIN(m_msg); \
|
||||||
|
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter ' " _STR(m_param) " ' is null."); \
|
||||||
|
return m_retval; \
|
||||||
|
} \
|
||||||
|
_err_error_exists = false; \
|
||||||
|
}
|
||||||
|
|
||||||
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
||||||
* the function will exit.
|
* the function will exit.
|
||||||
*/
|
*/
|
||||||
|
@ -214,6 +273,16 @@ extern bool _err_error_exists;
|
||||||
_err_error_exists = false; \
|
_err_error_exists = false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ERR_FAIL_COND_MSG(m_cond, m_msg) \
|
||||||
|
{ \
|
||||||
|
if (unlikely(m_cond)) { \
|
||||||
|
ERR_EXPLAIN(m_msg); \
|
||||||
|
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true."); \
|
||||||
|
return; \
|
||||||
|
} \
|
||||||
|
_err_error_exists = false; \
|
||||||
|
}
|
||||||
|
|
||||||
/** Use this one if there is no sensible fallback, that is, the error is unrecoverable.
|
/** Use this one if there is no sensible fallback, that is, the error is unrecoverable.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -225,6 +294,15 @@ extern bool _err_error_exists;
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define CRASH_COND_MSG(m_cond, m_msg) \
|
||||||
|
{ \
|
||||||
|
if (unlikely(m_cond)) { \
|
||||||
|
ERR_EXPLAIN(m_msg); \
|
||||||
|
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Condition ' " _STR(m_cond) " ' is true."); \
|
||||||
|
GENERATE_TRAP \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
||||||
* the function will exit.
|
* the function will exit.
|
||||||
* This function returns an error value, if returning Error, please select the most
|
* This function returns an error value, if returning Error, please select the most
|
||||||
|
@ -240,6 +318,16 @@ extern bool _err_error_exists;
|
||||||
_err_error_exists = false; \
|
_err_error_exists = false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ERR_FAIL_COND_V_MSG(m_cond, m_retval, m_msg) \
|
||||||
|
{ \
|
||||||
|
if (unlikely(m_cond)) { \
|
||||||
|
ERR_EXPLAIN(m_msg); \
|
||||||
|
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. returned: " _STR(m_retval)); \
|
||||||
|
return m_retval; \
|
||||||
|
} \
|
||||||
|
_err_error_exists = false; \
|
||||||
|
}
|
||||||
|
|
||||||
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
||||||
* the loop will skip to the next iteration.
|
* the loop will skip to the next iteration.
|
||||||
*/
|
*/
|
||||||
|
@ -253,6 +341,16 @@ extern bool _err_error_exists;
|
||||||
_err_error_exists = false; \
|
_err_error_exists = false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ERR_CONTINUE_MSG(m_cond, m_msg) \
|
||||||
|
{ \
|
||||||
|
if (unlikely(m_cond)) { \
|
||||||
|
ERR_EXPLAIN(m_msg); \
|
||||||
|
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Continuing..:"); \
|
||||||
|
continue; \
|
||||||
|
} \
|
||||||
|
_err_error_exists = false; \
|
||||||
|
}
|
||||||
|
|
||||||
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
|
||||||
* the loop will break
|
* the loop will break
|
||||||
*/
|
*/
|
||||||
|
@ -266,6 +364,16 @@ extern bool _err_error_exists;
|
||||||
_err_error_exists = false; \
|
_err_error_exists = false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ERR_BREAK_MSG(m_cond, m_msg) \
|
||||||
|
{ \
|
||||||
|
if (unlikely(m_cond)) { \
|
||||||
|
ERR_EXPLAIN(m_msg); \
|
||||||
|
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Breaking..:"); \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
_err_error_exists = false; \
|
||||||
|
}
|
||||||
|
|
||||||
/** Print an error string and return
|
/** Print an error string and return
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -276,6 +384,12 @@ extern bool _err_error_exists;
|
||||||
return; \
|
return; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ERR_FAIL_MSG(m_msg) \
|
||||||
|
{ \
|
||||||
|
ERR_EXPLAIN(m_msg); \
|
||||||
|
ERR_FAIL(); \
|
||||||
|
}
|
||||||
|
|
||||||
/** Print an error string and return with value
|
/** Print an error string and return with value
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -286,6 +400,12 @@ extern bool _err_error_exists;
|
||||||
return m_value; \
|
return m_value; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ERR_FAIL_V_MSG(m_value, m_msg) \
|
||||||
|
{ \
|
||||||
|
ERR_EXPLAIN(m_msg); \
|
||||||
|
ERR_FAIL_V(m_value); \
|
||||||
|
}
|
||||||
|
|
||||||
/** Use this one if there is no sensible fallback, that is, the error is unrecoverable.
|
/** Use this one if there is no sensible fallback, that is, the error is unrecoverable.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -295,6 +415,12 @@ extern bool _err_error_exists;
|
||||||
GENERATE_TRAP \
|
GENERATE_TRAP \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define CRASH_NOW_MSG(m_msg) \
|
||||||
|
{ \
|
||||||
|
ERR_EXPLAIN(m_msg); \
|
||||||
|
CRASH_NOW(); \
|
||||||
|
}
|
||||||
|
|
||||||
/** Print an error string.
|
/** Print an error string.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -355,4 +481,15 @@ extern bool _err_error_exists;
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define WARN_DEPRECATED_MSG(m_msg) \
|
||||||
|
{ \
|
||||||
|
static volatile bool warning_shown = false; \
|
||||||
|
if (!warning_shown) { \
|
||||||
|
ERR_EXPLAIN(m_msg); \
|
||||||
|
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "This method has been deprecated and will be removed in the future", ERR_HANDLER_WARNING); \
|
||||||
|
_err_error_exists = false; \
|
||||||
|
warning_shown = true; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue