18 #ifndef FOEDUS_ERROR_STACK_HPP_
19 #define FOEDUS_ERROR_STACK_HPP_
164 const char*
get_func(uint16_t stack_index)
const;
173 void output(std::ostream* ptr)
const;
211 mutable const char* custom_message_;
237 uint16_t stack_depth_;
240 mutable bool checked_;
255 stack_depth_(0), checked_(true) {
259 : custom_message_(
CXX11_NULLPTR), os_errno_(errno), error_code_(code),
260 stack_depth_(0), checked_(false) {
264 ErrorCode code,
const char* custom_message)
265 : custom_message_(
CXX11_NULLPTR), os_errno_(errno), error_code_(code), stack_depth_(1),
268 filenames_[0] = filename;
270 linenums_[0] = linenum;
280 const char* func, uint32_t linenum,
const char* more_custom_message)
291 filenames_[stack_depth_] = filename;
292 funcs_[stack_depth_] = func;
293 linenums_[stack_depth_] = linenum;
297 if (more_custom_message) {
311 custom_message_ = other.custom_message_;
313 stack_depth_ = other.stack_depth_;
314 for (
int i = 0; i < other.stack_depth_; ++i) {
315 filenames_[i] = other.filenames_[i];
316 funcs_[i] = other.funcs_[i];
317 linenums_[i] = other.linenums_[i];
319 os_errno_ = other.os_errno_;
320 error_code_ = other.error_code_;
322 other.checked_ =
true;
341 delete[] custom_message_;
355 size_t len = std::strlen(message);
356 char *copied =
new char[len + 1];
358 custom_message_ = copied;
359 std::memcpy(copied, message, len + 1);
370 if (custom_message_) {
372 size_t cur_len = std::strlen(custom_message_);
373 size_t more_len = std::strlen(more_custom_message);
374 char *copied =
new char[cur_len + more_len + 1];
376 custom_message_ = copied;
377 std::memcpy(copied, custom_message_, cur_len);
378 std::memcpy(copied + cur_len, more_custom_message, more_len + 1);
404 return custom_message_;
421 return linenums_[stack_index];
430 return filenames_[stack_index];
439 return funcs_[stack_index];
456 dump_and_abort(
"Return value is not checked. ErrorStack must be checked");
480 #define ERROR_STACK(e) foedus::ErrorStack(__FILE__, __FUNCTION__, __LINE__, e)
498 #define ERROR_STACK_MSG(e, m) foedus::ErrorStack(__FILE__, __FUNCTION__, __LINE__, e, m)
517 #define CHECK_ERROR(x)\
519 foedus::ErrorStack __e(x);\
520 if (UNLIKELY(__e.is_error())) {\
521 return foedus::ErrorStack(__e, __FILE__, __FUNCTION__, __LINE__);\
533 #define WRAP_ERROR_CODE(x)\
535 foedus::ErrorCode __e = x;\
536 if (UNLIKELY(__e != foedus::kErrorCodeOk)) {return ERROR_STACK(__e);}\
547 #define UNWRAP_ERROR_STACK(x)\
549 foedus::ErrorStack __e = x;\
550 if (UNLIKELY(__e.is_error())) { return __e.get_error_code(); }\
566 #define CHECK_ERROR_MSG(x, m)\
568 foedus::ErrorStack __e(x);\
569 if (UNLIKELY(__e.is_error())) {\
570 return foedus::ErrorStack(__e, __FILE__, __FUNCTION__, __LINE__, m);\
590 #define CHECK_OUTOFMEMORY(ptr)\
591 if (UNLIKELY(!ptr)) {\
592 return foedus::ErrorStack(__FILE__, __FUNCTION__, __LINE__, kErrorCodeOutofmemory);\
610 #define COERCE_ERROR(x)\
612 foedus::ErrorStack __e(x);\
613 if (UNLIKELY(__e.is_error())) {\
614 __e.dump_and_abort("Unexpected error happened");\
625 #define COERCE_ERROR_CODE(x)\
627 foedus::ErrorCode __e = x;\
628 if (UNLIKELY(__e != foedus::kErrorCodeOk)) {\
629 ERROR_STACK(__e).dump_and_abort("Unexpected error happened");\
633 #endif // FOEDUS_ERROR_STACK_HPP_
static std::string get_recent_dump_and_abort()
Signal handler can get the dump information via this.
#define CXX11_NULLPTR
Used in public headers in place of "nullptr" of C++11.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Brings error stacktrace information as return value of functions.
#define LIKELY(x)
Hints that x is highly likely true.
ErrorStack & operator=(const ErrorStack &other)
Assignment operator.
void append_custom_message(const char *more_custom_message)
Appends more custom error message at the end.
const char * get_filename(uint16_t stack_index) const
Returns the file name of the given stack position.
ErrorCode get_error_code() const
Return the integer error code.
friend std::ostream & operator<<(std::ostream &o, const ErrorStack &obj)
Maximum stack trace depth.
uint16_t get_stack_depth() const
Returns the depth of stack this error code has collected.
void dump_and_abort(const char *abort_message) const
Describe this object to std::cerr and then abort.
uint32_t get_linenum(uint16_t stack_index) const
Returns the line number of the given stack position.
const char * get_custom_message() const
Returns the custom error message.
const char * get_func(uint16_t stack_index) const
Returns the function name of the given stack position.
void output(std::ostream *ptr) const
Describe this object to the given stream.
const char * get_message() const
Returns the error message inferred by the error code.
const ErrorStack kRetOk
Normal return value for no-error case.
const char * get_error_message(ErrorCode code)
Returns the error messages corresponding to ErrorCode enum defined in error_code.xmacro.
void copy_custom_message(const char *message)
Copy the given custom message into this object.
Constants
Constant values.
~ErrorStack()
Will warn in stderr if the error code is not checked yet.
int get_os_errno() const
Global errno of the system as of instantiation of this error stack.
#define UNLIKELY(x)
Hints that x is highly likely false.
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
void clear_custom_message()
Deletes custom message from this object.
void verify() const
Output a warning to stderr if the error is not checked yet.
ErrorCode
Enum of error codes defined in error_code.xmacro.
bool is_error() const
Returns if this return code is not kErrorCodeOk.
ErrorStack()
Empty constructor.