diff --git a/be/src/common/exception.cpp b/be/src/common/exception.cpp index c6139c0f995fa3..48e1229d44e83b 100644 --- a/be/src/common/exception.cpp +++ b/be/src/common/exception.cpp @@ -32,23 +32,4 @@ Exception::Exception(int code, const std::string_view& msg) { LOG(FATAL) << "[ExitOnException] error code: " << code << ", message: " << msg; } } - -Exception::Exception(const Exception& nested, int code, const std::string_view& msg) { - _code = code; - _err_msg = std::make_unique(); - _err_msg->_msg = msg; - if (ErrorCode::error_states[abs(code)].stacktrace) { - _err_msg->_stack = get_stack_trace(); - } - _nested_excption = std::make_unique(); - _nested_excption->_code = nested._code; - _nested_excption->_err_msg = std::make_unique(); - _nested_excption->_err_msg->_msg = nested._err_msg->_msg; - _nested_excption->_err_msg->_stack = nested._err_msg->_stack; - - if (config::exit_on_exception) { - LOG(FATAL) << "[ExitOnException] error code: " << code << ", message: " << msg; - } -} - } // namespace doris \ No newline at end of file diff --git a/be/src/common/exception.h b/be/src/common/exception.h index ce44e6587499b4..b35ef7e8ff8fce 100644 --- a/be/src/common/exception.h +++ b/be/src/common/exception.h @@ -19,8 +19,8 @@ #include #include -#include +#include #include #include #include @@ -39,9 +39,6 @@ class Exception : public std::exception { Exception() : _code(ErrorCode::OK) {} Exception(int code, const std::string_view& msg); Exception(const Status& status) : Exception(status.code(), status.msg()) {} - // add nested exception as first param, or the template may could not find - // the correct method for ...args - Exception(const Exception& nested, int code, const std::string_view& msg); // Format message with fmt::format, like the logging functions. template @@ -63,7 +60,6 @@ class Exception : public std::exception { std::string _stack; }; std::unique_ptr _err_msg; - std::unique_ptr _nested_excption; mutable std::string _cache_string; }; @@ -71,16 +67,12 @@ inline const std::string& Exception::to_string() const { if (!_cache_string.empty()) { return _cache_string; } - std::stringstream ostr; - ostr << "[E" << _code << "] "; - ostr << (_err_msg ? _err_msg->_msg : ""); + fmt::memory_buffer buf; + fmt::format_to(buf, "[E{}] {}", _code, _err_msg ? _err_msg->_msg : ""); if (_err_msg && !_err_msg->_stack.empty()) { - ostr << '\n' << _err_msg->_stack; + fmt::format_to(buf, "\n{}", _err_msg->_stack); } - if (_nested_excption != nullptr) { - ostr << '\n' << "Caused by:" << _nested_excption->to_string(); - } - _cache_string = ostr.str(); + _cache_string = fmt::to_string(buf); return _cache_string; } diff --git a/be/test/common/exception_test.cpp b/be/test/common/exception_test.cpp index 344c0bb1fafcbd..0878c3942810c0 100644 --- a/be/test/common/exception_test.cpp +++ b/be/test/common/exception_test.cpp @@ -50,12 +50,6 @@ TEST_F(ExceptionTest, NestedError) { throw doris::Exception(ErrorCode::OS_ERROR, "test OS_ERROR {}", "bug"); } catch (doris::Exception& e1) { EXPECT_TRUE(e1.to_string().find("OS_ERROR") != std::string::npos); - try { - throw doris::Exception(e1, ErrorCode::INVALID_ARGUMENT, "test INVALID_ARGUMENT"); - } catch (doris::Exception& e2) { - EXPECT_TRUE(e2.to_string().find("OS_ERROR") != std::string::npos); - EXPECT_TRUE(e2.to_string().find("INVALID_ARGUMENT") != std::string::npos); - } } }