libfoedus-core
FOEDUS Core Library
|
Brings error stacktrace information as return value of functions. More...
Brings error stacktrace information as return value of functions.
This is returned by many API functions. As it brings stacktrace information, it's more informative than just returning ErrorCode. However, note that instantiating and augmenting this stack object has some overhead.
This class is header-only except output(), dump_and_abort(), and std::ostream redirect.
Definition at line 81 of file error_stack.hpp.
#include <error_stack.hpp>
Public Types | |
enum | Constants { kMaxStackDepth = 8 } |
Constant values. More... | |
Public Member Functions | |
ErrorStack () | |
Empty constructor. More... | |
ErrorStack (ErrorCode code) | |
Instantiate a return code without a custom error message nor stacktrace. More... | |
ErrorStack (const char *filename, const char *func, uint32_t linenum, ErrorCode code, const char *custom_message=nullptr) | |
Instantiate a return code with stacktrace and optionally a custom error message. More... | |
ErrorStack (const ErrorStack &other) | |
Copy constructor. More... | |
ErrorStack (const ErrorStack &other, const char *filename, const char *func, uint32_t linenum, const char *more_custom_message=nullptr) | |
Copy constructor to augment the stacktrace. More... | |
ErrorStack & | operator= (const ErrorStack &other) |
Assignment operator. More... | |
~ErrorStack () | |
Will warn in stderr if the error code is not checked yet. More... | |
bool | is_error () const |
Returns if this return code is not kErrorCodeOk. More... | |
ErrorCode | get_error_code () const |
Return the integer error code. More... | |
const char * | get_message () const |
Returns the error message inferred by the error code. More... | |
const char * | get_custom_message () const |
Returns the custom error message. More... | |
void | copy_custom_message (const char *message) |
Copy the given custom message into this object. More... | |
void | clear_custom_message () |
Deletes custom message from this object. More... | |
void | append_custom_message (const char *more_custom_message) |
Appends more custom error message at the end. More... | |
uint16_t | get_stack_depth () const |
Returns the depth of stack this error code has collected. More... | |
uint32_t | get_linenum (uint16_t stack_index) const |
Returns the line number of the given stack position. More... | |
const char * | get_filename (uint16_t stack_index) const |
Returns the file name of the given stack position. More... | |
const char * | get_func (uint16_t stack_index) const |
Returns the function name of the given stack position. More... | |
int | get_os_errno () const |
Global errno of the system as of instantiation of this error stack. More... | |
void | verify () const |
Output a warning to stderr if the error is not checked yet. More... | |
void | output (std::ostream *ptr) const |
Describe this object to the given stream. More... | |
void | dump_and_abort (const char *abort_message) const |
Describe this object to std::cerr and then abort. More... | |
Static Public Member Functions | |
static std::string | get_recent_dump_and_abort () |
Signal handler can get the dump information via this. More... | |
Friends | |
std::ostream & | operator<< (std::ostream &o, const ErrorStack &obj) |
Constant values.
Enumerator | |
---|---|
kMaxStackDepth |
Maximum stack trace depth. |
Definition at line 84 of file error_stack.hpp.
|
inline |
Empty constructor.
This is same as duplicating kRetOk.
Definition at line 253 of file error_stack.hpp.
|
inlineexplicit |
Instantiate a return code without a custom error message nor stacktrace.
[in] | code | Error code, either kErrorCodeOk or real errors. |
This is the most (next to kRetOk) light-weight way to create/propagate a return code. Use this one if you do not need a detail information to debug the error (eg, error whose cause is obvious, an expected error that is immediately caught, etc).
Definition at line 258 of file error_stack.hpp.
|
inline |
Instantiate a return code with stacktrace and optionally a custom error message.
[in] | filename | file name of the current place. It must be a const and permanent string, such as what "__FILE__" returns. Note that we do NOT do deep-copy of the strings. |
[in] | func | functiona name of the current place. Must be a const-permanent as well, such as "__FUNCTION__" of gcc/MSVC or C++11's func. |
[in] | linenum | line number of the current place. Usually "__LINE__". |
[in] | code | Error code, must be real errors. |
[in] | custom_message | Optional custom error message in addition to the default one inferred from error code. If you pass a non-NULL string to this argument, we do deep-copy, so it's EXPENSIVE! |
Definition at line 263 of file error_stack.hpp.
References ASSERT_ND, copy_custom_message(), and foedus::kErrorCodeOk.
|
inline |
Copy constructor.
Definition at line 274 of file error_stack.hpp.
References operator=().
|
inline |
Copy constructor to augment the stacktrace.
Definition at line 279 of file error_stack.hpp.
References append_custom_message(), foedus::kErrorCodeOk, kMaxStackDepth, LIKELY, and operator=().
|
inline |
Will warn in stderr if the error code is not checked yet.
Definition at line 326 of file error_stack.hpp.
References clear_custom_message(), foedus::kErrorCodeOk, LIKELY, and verify().
|
inline |
Appends more custom error message at the end.
Definition at line 364 of file error_stack.hpp.
References copy_custom_message(), foedus::kErrorCodeOk, and LIKELY.
Referenced by ErrorStack().
|
inline |
Deletes custom message from this object.
Definition at line 339 of file error_stack.hpp.
References CXX11_NULLPTR, and UNLIKELY.
Referenced by copy_custom_message(), and ~ErrorStack().
|
inline |
Copy the given custom message into this object.
Definition at line 346 of file error_stack.hpp.
References clear_custom_message(), foedus::kErrorCodeOk, and LIKELY.
Referenced by append_custom_message(), and ErrorStack().
void foedus::ErrorStack::dump_and_abort | ( | const char * | abort_message | ) | const |
Describe this object to std::cerr and then abort.
This also leaves the dump information in static variable so that a signal handler pick it up.
Definition at line 61 of file error_stack.cpp.
References ASSERT_ND, and foedus::print_backtrace().
Referenced by verify().
|
inline |
Returns the custom error message.
Definition at line 399 of file error_stack.hpp.
References CXX11_NULLPTR, and foedus::kErrorCodeOk.
Referenced by foedus::FixedErrorStack::from_error_stack(), foedus::FixedErrorStack::operator=(), and output().
|
inline |
Return the integer error code.
Definition at line 390 of file error_stack.hpp.
Referenced by foedus::FixedErrorStack::from_error_stack(), and foedus::FixedErrorStack::operator=().
|
inline |
Returns the file name of the given stack position.
Definition at line 424 of file error_stack.hpp.
References ASSERT_ND, CXX11_NULLPTR, and foedus::kErrorCodeOk.
Referenced by foedus::FixedErrorStack::from_error_stack(), foedus::FixedErrorStack::operator=(), and output().
|
inline |
Returns the function name of the given stack position.
Definition at line 433 of file error_stack.hpp.
References ASSERT_ND, CXX11_NULLPTR, and foedus::kErrorCodeOk.
Referenced by foedus::FixedErrorStack::from_error_stack(), foedus::FixedErrorStack::operator=(), and output().
|
inline |
Returns the line number of the given stack position.
Definition at line 415 of file error_stack.hpp.
References ASSERT_ND, and foedus::kErrorCodeOk.
Referenced by foedus::FixedErrorStack::from_error_stack(), foedus::FixedErrorStack::operator=(), and output().
|
inline |
Returns the error message inferred by the error code.
Definition at line 395 of file error_stack.hpp.
References foedus::get_error_message().
Referenced by output().
|
inline |
Global errno of the system as of instantiation of this error stack.
Definition at line 442 of file error_stack.hpp.
References foedus::kErrorCodeOk.
Referenced by foedus::FixedErrorStack::from_error_stack(), and foedus::FixedErrorStack::operator=().
|
static |
Signal handler can get the dump information via this.
Definition at line 74 of file error_stack.cpp.
References foedus::static_recent_dump_and_abort.
|
inline |
Returns the depth of stack this error code has collected.
Definition at line 407 of file error_stack.hpp.
References foedus::kErrorCodeOk.
Referenced by foedus::FixedErrorStack::from_error_stack(), foedus::FixedErrorStack::operator=(), and output().
|
inline |
Returns if this return code is not kErrorCodeOk.
Definition at line 385 of file error_stack.hpp.
References foedus::kErrorCodeOk.
Referenced by foedus::soc::SocManagerPimpl::child_main_common(), foedus::storage::StorageManagerPimpl::create_storage_apply(), foedus::soc::SocManagerPimpl::emulated_child_main(), foedus::soc::SocManagerPimpl::forked_child_main(), foedus::FixedErrorStack::from_error_stack(), foedus::snapshot::SnapshotManagerPimpl::glean_logs(), foedus::snapshot::SnapshotManagerPimpl::handle_snapshot(), foedus::thread::ThreadPimpl::handle_tasks(), foedus::DefaultInitializable::initialize(), foedus::soc::SocManagerPimpl::initialize_child(), foedus::soc::SocManagerPimpl::initialize_master(), foedus::EnginePimpl::initialize_once(), foedus::FixedErrorStack::operator=(), output(), foedus::ErrorStackBatch::push_back(), foedus::externalize::Externalizable::save_to_stream(), foedus::soc::SocManagerPimpl::spawned_child_main(), and foedus::UninitializeGuard::~UninitializeGuard().
|
inline |
Assignment operator.
Definition at line 302 of file error_stack.hpp.
References CXX11_NULLPTR, foedus::kErrorCodeOk, and LIKELY.
Referenced by ErrorStack().
void foedus::ErrorStack::output | ( | std::ostream * | ptr | ) | const |
Describe this object to the given stream.
Definition at line 30 of file error_stack.cpp.
References get_custom_message(), foedus::get_error_name(), get_filename(), get_func(), get_linenum(), get_message(), get_stack_depth(), is_error(), kMaxStackDepth, and foedus::assorted::os_error().
Referenced by foedus::operator<<().
|
inline |
Output a warning to stderr if the error is not checked yet.
Definition at line 450 of file error_stack.hpp.
References dump_and_abort(), foedus::kErrorCodeOk, and LIKELY.
Referenced by ~ErrorStack().
|
friend |
Definition at line 78 of file error_stack.cpp.