112 w_rc_t(
const char* filename, uint32_t linenum,
w_error_codes error_code,
const char* custom_message =
nullptr);
118 w_rc_t(
const w_rc_t& other,
const char* filename, uint32_t linenum,
const char* more_custom_message =
nullptr);
221 for (uint16_t stack_index = 0; stack_index < obj.
get_stack_depth(); ++stack_index) {
225 o << std::endl <<
" .. and more. Increase MAX_RCT_STACK_DEPTH to see full stacktraces";
248 #define RC(e) w_rc_t(__FILE__, __LINE__, e) 264 #define RC_AUGMENT(rc) w_rc_t(rc, __FILE__, __LINE__) 275 #define RC_APPEND_MSG(rc, m) \ 277 std::stringstream os; \ 279 rc.append_custom_message(os.str().c_str()); \ 287 #define W_RETURN_RC_MSG(e, m) \ 289 w_rc_t __e(__FILE__, __LINE__, e); \ 290 RC_APPEND_MSG(__e, m); \ 307 if (__e.is_error()) {return RC_AUGMENT(__e);} \ 318 #define W_DO_MSG(x, m) \ 321 if (__e.is_error()) { \ 323 RC_APPEND_MSG(__e, m); \ 349 #define W_COERCE(x) \ 352 if (__e.is_error()) { \ 353 __e = RC_AUGMENT(__e); \ 363 #define W_COERCE_MSG(x, m) \ 366 if (__em.is_error()) { \ 367 __em = RC_AUGMENT(__em); \ 368 RC_APPEND_MSG(__em, m); \ 378 #define W_FATAL(e) W_COERCE(RC(e)) 385 #define W_FATAL_MSG(e, m) W_COERCE_MSG(RC(e), m) 392 #define W_IGNORE(x) ((void) x.is_error()) 414 #if W_DEBUG_LEVEL >= 5 415 std::cout <<
"Error instantiated: " << *
this << std::endl;
416 #endif //W_DEBUG_LEVEL>=3 431 ::memcpy(
this, &other,
sizeof(
w_rc_t));
438 char* copied =
new char[len + 1];
445 inline w_rc_t::w_rc_t(
const w_rc_t& other,
const char* filename, uint32_t linenum,
const char* more_custom_message) {
460 if (more_custom_message !=
nullptr) {
463 #if W_DEBUG_LEVEL >= 5 464 std::cout <<
"Error augmented: " << *
this << std::endl;
465 #endif //W_DEBUG_LEVEL>=3 473 #if W_DEBUG_LEVEL > 0 476 #endif // W_DEBUG_LEVEL>0 489 size_t more_len = ::strlen(more_custom_message);
493 char* copied =
new char[cur_len + more_len + 1];
496 ::memcpy(copied + cur_len, more_custom_message, more_len + 1);
499 char* copied =
new char[more_len + 1];
501 ::memcpy(copied, more_custom_message, more_len + 1);
560 std::cerr <<
"WARNING: Return value is not checked. w_rc_t must be checked before deallocation." << std::endl;
561 std::cerr <<
"Error detail:" << *
this << std::endl;
570 std::cerr <<
"FATAL: Unexpected error happened. Will exit." << std::endl;
571 std::cerr <<
"Error detail:" << *
this << std::endl;
~w_rc_t()
Definition: w_rc.h:468
w_error_codes err_num() const
Definition: w_rc.h:510
uint16_t _stack_depth
Current stack depth. Value 0 implies that we don't pass around stacktrace for this return code...
Definition: w_rc.h:205
const w_rc_t RCOK
Definition: w_rc.h:239
bool is_error() const
True if this return code is not RCOK or equivalent. This must be called for every w_rc_t before destr...
Definition: w_rc.h:505
uint16_t get_linenum(uint16_t stack_index) const
Definition: w_rc.h:536
w_rc_t()
Definition: w_rc.h:394
bool _checked
Whether someone already checked the error code of this object.
Definition: w_rc.h:208
const char * _filenames[MAX_RCT_STACK_DEPTH]
Filenames of stacktraces. This is deep-first, so _filenames[0] is where the w_rc_t was initially inst...
Definition: w_rc.h:179
void verify() const
Definition: w_rc.h:554
const char * get_custom_message() const
Definition: w_rc.h:520
const char * get_filename(uint16_t stack_index) const
Definition: w_rc.h:545
w_error_codes
Enum of error codes defined in w_error_xmacro.h.
Definition: w_error.h:43
w_error_codes _error_code
Integer error code.
Definition: w_rc.h:199
uint16_t get_stack_depth() const
Definition: w_rc.h:528
Return code for most functions and methods.
Definition: w_rc.h:87
w_rc_t rc_t
Definition: w_rc.h:211
uint16_t _linenums[MAX_RCT_STACK_DEPTH]
Line numbers of stacktraces.
Definition: w_rc.h:182
const char * _custom_message
Optional custom error message. We deep-copy this string if it's non-NULL. The reason why we don't use...
Definition: w_rc.h:190
std::ostream & operator<<(std::ostream &o, const w_rc_t &obj)
Definition: w_rc.h:213
void append_custom_message(const char *more_custom_message)
Definition: w_rc.h:483
const char * get_message() const
Definition: w_rc.h:515
void fatal() const
Fail catastrophically after describing the error. This is called from W_COERCE to handle an unexpecte...
Definition: w_rc.h:565
const uint16_t MAX_RCT_STACK_DEPTH
Constant to define maximum stack trace depth for w_rc_t.
Definition: w_rc.h:62
w_rc_t & operator=(w_rc_t const &other)
Definition: w_rc.h:423