[bugfix](exception) remove fmt code to test if there still exist core (#19009)

This commit is contained in:
yiguolei
2023-04-25 07:24:14 +08:00
committed by GitHub
parent 3899c08036
commit 4e9b32d622

View File

@ -45,14 +45,10 @@ public:
Exception(int code, const std::string_view fmt, Args&&... args)
: Exception(code, fmt::format(fmt, std::forward<Args>(args)...)) {}
std::string code_as_string() const { return fmt::format("E{}", _code); }
int code() const { return _code; }
std::string to_string() const;
friend std::ostream& operator<<(std::ostream& ostr, const Exception& exp);
private:
int _code;
struct ErrMsg {
@ -63,22 +59,17 @@ private:
std::unique_ptr<Exception> _nested_excption;
};
inline std::ostream& operator<<(std::ostream& ostr, const Exception& exp) {
ostr << '[' << exp.code_as_string() << "] ";
ostr << (exp._err_msg ? exp._err_msg->_msg : "");
if (exp._err_msg && !exp._err_msg->_stack.empty()) {
ostr << '\n' << exp._err_msg->_stack;
}
if (exp._nested_excption != nullptr) {
ostr << '\n' << "Caused by:" << *exp._nested_excption;
}
return ostr;
}
inline std::string Exception::to_string() const {
std::stringstream ss;
ss << *this;
return ss.str();
std::stringstream ostr;
ostr << "[E" << _code << "] ";
ostr << (_err_msg ? _err_msg->_msg : "");
if (_err_msg && !_err_msg->_stack.empty()) {
ostr << '\n' << _err_msg->_stack;
}
if (_nested_excption != nullptr) {
ostr << '\n' << "Caused by:" << _nested_excption->to_string();
}
return ostr.str();
}
} // namespace doris