diff options
| author | Pedro J. Estébanez | 2017-05-26 21:11:16 +0200 |
|---|---|---|
| committer | Pedro J. Estébanez | 2017-07-05 09:31:44 +0200 |
| commit | 211c4518903d82068c061943064824ac5595fd38 (patch) | |
| tree | 5c332554f6df617d5d9d9eb81f1e471517231fbf /core/error_macros.h | |
| parent | 9fa4f1c54c6d528192e7ed04354d5ce2c733d99a (diff) | |
| download | godot-211c4518903d82068c061943064824ac5595fd38.tar.gz godot-211c4518903d82068c061943064824ac5595fd38.tar.zst godot-211c4518903d82068c061943064824ac5595fd38.zip | |
Diffstat (limited to 'core/error_macros.h')
| -rw-r--r-- | core/error_macros.h | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/core/error_macros.h b/core/error_macros.h index 00fced358..6c803951a 100644 --- a/core/error_macros.h +++ b/core/error_macros.h @@ -115,6 +115,19 @@ extern bool _err_error_exists; #define FUNCTION_STR __FUNCTION__ #endif +// Don't use this directly; instead, use any of the CRASH_* macros +#ifdef _MSC_VER +#define GENERATE_TRAP \ + __debugbreak(); \ + /* Avoid warning about control paths */ \ + for (;;) { \ + } +#else +#define GENERATE_TRAP __builtin_trap(); +#endif + +// (*): See https://stackoverflow.com/questions/257418/do-while-0-what-is-it-good-for + #define ERR_FAIL_INDEX(m_index, m_size) \ do { \ if ((m_index) < 0 || (m_index) >= (m_size)) { \ @@ -122,12 +135,12 @@ extern bool _err_error_exists; return; \ } else \ _err_error_exists = false; \ - } while (0); + } while (0); // (*) /** An index has failed if m_index<0 or m_index >=m_size, the function exists. - * This function returns an error value, if returning Error, please select the most - * appropriate error condition from error_macros.h - */ +* This function returns an error value, if returning Error, please select the most +* appropriate error condition from error_macros.h +*/ #define ERR_FAIL_INDEX_V(m_index, m_size, m_retval) \ do { \ @@ -136,7 +149,18 @@ extern bool _err_error_exists; return m_retval; \ } else \ _err_error_exists = false; \ - } while (0); + } while (0); // (*) + +/** 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. +*/ +#define CRASH_BAD_INDEX(m_index, m_size) \ + do { \ + if ((m_index) < 0 || (m_index) >= (m_size)) { \ + _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Index " _STR(m_index) " out of size (" _STR(m_size) ")."); \ + GENERATE_TRAP \ + } \ + } while (0); // (*) /** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert(). * the function will exit. @@ -173,6 +197,17 @@ extern bool _err_error_exists; _err_error_exists = false; \ } +/** Use this one if there is no sensible fallback, that is, the error is unrecoverable. + */ + +#define CRASH_COND(m_cond) \ + { \ + if (m_cond) { \ + _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(). * the function will exit. * This function returns an error value, if returning Error, please select the most @@ -234,6 +269,15 @@ extern bool _err_error_exists; return m_value; \ } +/** Use this one if there is no sensible fallback, that is, the error is unrecoverable. + */ + +#define CRASH_NOW() \ + { \ + _err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Method/Function Failed."); \ + GENERATE_TRAP \ + } + /** Print an error string. */ |
