Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions be/src/common/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ Exception::Exception(int code, const std::string_view& msg, bool from_status) {
// std::cout << "Exception: " << code << ", " << msg << ", " << get_stack_trace(0, "DISABLED")
// << std::endl;
#endif

fmt::memory_buffer buf;
fmt::format_to(buf, "[E{}] {}", _code, _err_msg->_msg);
if (!_err_msg->_stack.empty()) {
fmt::format_to(buf, "\n{}", _err_msg->_stack);
}
_cache_string = fmt::to_string(buf);

if (config::exit_on_exception) {
LOG(FATAL) << "[ExitOnException] error code: " << code << ", message: " << msg;
}
Expand Down
20 changes: 3 additions & 17 deletions be/src/common/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class Exception : public std::exception {
int code() const { return _code; }
std::string message() const { return _err_msg ? _err_msg->_msg : ""; }

const std::string& to_string() const;
const std::string& to_string() const { return _cache_string; }

const char* what() const noexcept override { return to_string().c_str(); }
const char* what() const noexcept override { return _cache_string.c_str(); }

Status to_status() const { return {code(), _err_msg->_msg, _err_msg->_stack}; }

Expand All @@ -61,22 +61,8 @@ class Exception : public std::exception {
std::string _stack;
};
std::unique_ptr<ErrMsg> _err_msg;
mutable std::string _cache_string;
std::string _cache_string {};
};

inline const std::string& Exception::to_string() const {
if (!_cache_string.empty()) {
return _cache_string;
}
fmt::memory_buffer buf;
fmt::format_to(buf, "[E{}] {}", _code, _err_msg ? _err_msg->_msg : "");
if (_err_msg && !_err_msg->_stack.empty()) {
fmt::format_to(buf, "\n{}", _err_msg->_stack);
}
_cache_string = fmt::to_string(buf);
return _cache_string;
}

} // namespace doris

#define RETURN_IF_CATCH_EXCEPTION(stmt) \
Expand Down
Loading