29 #ifndef HYPERTABLE_ERROR_H
30 #define HYPERTABLE_ERROR_H
289 std::ostream &
render(std::ostream &out)
const;
303 std::ostream &
render(std::ostream &out)
const;
340 Exception(
int error,
int l = 0,
const char *fn = 0,
const char *fl = 0)
341 : Parent(
""), m_error(error), m_line(l), m_func(fn), m_file(fl),
prev(0) {
354 : Parent(msg), m_error(error), m_line(l), m_func(fn), m_file(fl),
368 const char *fn = 0,
const char *fl = 0)
369 : Parent(msg), m_error(error), m_line(l), m_func(fn), m_file(fl),
378 : Parent(ex), m_error(ex.m_error), m_line(ex.m_line), m_func(ex.m_func),
416 return out << what();
426 const char *sep)
const;
446 inline std::ostream &
452 inline std::ostream &
458 inline std::ostream &
464 inline std::ostream &
470 #define HT_EXCEPTION(_code_, _msg_) \
471 Exception(_code_, _msg_, __LINE__, HT_FUNC, __FILE__)
474 #define HT_EXCEPTION2(_code_, _ex_, _msg_) \
475 Exception(_code_, _msg_, _ex_, __LINE__, HT_FUNC, __FILE__)
478 #define HT_THROW(_code_, _msg_) throw HT_EXCEPTION(_code_, _msg_)
481 #define HT_THROW_(_code_) HT_THROW(_code_, "")
484 #define HT_THROW2(_code_, _ex_, _msg_) throw HT_EXCEPTION2(_code_, _ex_, _msg_)
487 #define HT_THROW2_(_code_, _ex_) HT_THROW2(_code_, _ex_, "")
490 #define HT_THROWF(_code_, _fmt_, ...) \
491 throw HT_EXCEPTION(_code_, Hypertable::format(_fmt_, __VA_ARGS__))
494 #define HT_THROW2F(_code_, _ex_, _fmt_, ...) \
495 throw HT_EXCEPTION2(_code_, _ex_, Hypertable::format(_fmt_, __VA_ARGS__))
499 #define HT_RETHROWF(_fmt_, ...) \
500 catch (Exception &e) { HT_THROW2F(e.code(), e, _fmt_, __VA_ARGS__); } \
501 catch (std::bad_alloc &e) { \
502 HT_THROWF(Error::BAD_MEMORY_ALLOCATION, _fmt_, __VA_ARGS__); \
504 catch (std::exception &e) { \
505 HT_THROWF(Error::EXTERNAL, "caught std::exception: %s " _fmt_, e.what(), \
509 HT_ERRORF("caught unknown exception " _fmt_, __VA_ARGS__); \
514 #define HT_RETHROW(_s_) HT_RETHROWF("%s", _s_)
517 #define HT_TRY(_s_, _code_) do { \
523 #define HT_LOG_EXCEPTION(_s_) \
524 catch (Exception &e) { HT_ERROR_OUT << e <<", "<< _s_ << HT_END; } \
525 catch (std::bad_alloc &e) { \
526 HT_ERROR_OUT << "Out of memory, " << _s_ << HT_END; } \
527 catch (std::exception &e) { \
528 HT_ERROR_OUT << "Caught exception: " << e.what() <<", "<< _s_ << HT_END; } \
530 HT_ERROR_OUT << "Caught unknown exception, " << _s_ << HT_END; }
533 #define HT_TRY_OR_LOG(_s_, _code_) do { \
535 HT_LOG_EXCEPTION(_s_) \
542 #endif // HYPERTABLE_ERROR_H
ExceptionMessagesRenderer messages(const char *sep=": ") const
Retrieves a Renderer for chained Exceptions.
Exception(int error, int l=0, const char *fn=0, const char *fl=0)
Constructor.
const char * func() const
Returns the name of the function which threw the Exception.
std::string String
A String is simply a typedef to std::string.
virtual std::ostream & render_messages(std::ostream &out, const char *sep) const
Renders multiple Exceptions to an ostream.
virtual std::ostream & render_message(std::ostream &out) const
Renders an Exception to an ostream.
void generate_html_error_code_documentation(std::ostream &out)
Generates and print the error documentation as html.
std::runtime_error Parent
std::ostream & render(std::ostream &out) const
Global helper function to print an Exception to a std::ostream.
const char * get_text(int error)
Returns a descriptive error message.
ExceptionMessageRenderer message() const
Retrieves a Renderer for this Exception.
int m_error
The error code.
std::ostream & operator<<(std::ostream &os, const crontab_entry &entry)
Helper function to write crontab_entry to an ostream.
const char * file() const
Returns the source code line number where the exception was thrown.
ExceptionMessageRenderer(const Exception &e)
Exception(int error, const String &msg, int l=0, const char *fn=0, const char *fl=0)
Constructor.
std::ostream & render(std::ostream &out) const
Global helper function to print an Exception to a std::ostream.
Helper class to render an exception message a la IO manipulators.
Exception * prev
The previous exception in the exception chain.
Exception(int error, const String &msg, const Exception &ex, int l=0, const char *fn=0, const char *fl=0)
Constructor.
ExceptionMessagesRenderer(const Exception &e, const char *sep=": ")
This is a generic exception class for Hypertable.
int m_line
The source code line where the exception was thrown.
A String class based on std::string.
const char * m_file
The source code file where the exception was thrown.
Exception(const Exception &ex)
Copy constructor.
Helper class to render an exception message a la IO manipulators.
const char * m_func
The function name where the exception was thrown.
int line() const
Returns the source code line number where the exception was thrown.
int code() const
Returns the error code.
const Exception & operator=(const Exception &)
Do not allow assignments.