Files
doris/be/test/common/exception_test.cpp
yiguolei 9213dd906a [enhancement](exception) add exception structure and using unique ptr in VExplodeBitmapTableFunction (#17531)
add exception class in common.
using unique ptr in VExplodeBitmapTableFunction
support single exception or nested exception, like this:

---SingleException
[E-100] test OS_ERROR bug
@ 0x55e80b93c0d9 doris::Exception::Exception<>()
@ 0x55e80b938df1 doris::ExceptionTest_NestedError_Test::TestBody()
@ 0x55e82e16bafb testing::internal::HandleSehExceptionsInMethodIfSupported<>()
@ 0x55e82e15ab3a testing::internal::HandleExceptionsInMethodIfSupported<>()
@ 0x55e82e1361e3 testing::Test::Run()
@ 0x55e82e136f29 testing::TestInfo::Run()
@ 0x55e82e1376e4 testing::TestSuite::Run()
@ 0x55e82e148042 testing::internal::UnitTestImpl::RunAllTests()
@ 0x55e82e16dcab testing::internal::HandleSehExceptionsInMethodIfSupported<>()
@ 0x55e82e15ce4a testing::internal::HandleExceptionsInMethodIfSupported<>()
@ 0x55e82e147bab testing::UnitTest::Run()
@ 0x55e80c4b39e3 RUN_ALL_TESTS()
@ 0x55e80c4a99b5 main
@ 0x7f0a619d0493 __libc_start_main
@ 0x55e80b84602a _start
@ (nil) (unknown)
2023-03-08 10:44:14 +08:00

61 lines
1.9 KiB
C++

// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#include "common/exception.h"
#include <gtest/gtest.h>
#include <iostream>
#include <string>
namespace doris {
class ExceptionTest : public testing::Test {};
TEST_F(ExceptionTest, OK) {
// default
try {
throw doris::Exception();
} catch (doris::Exception& e) {
EXPECT_TRUE(e.code() == ErrorCode::OK);
}
}
TEST_F(ExceptionTest, SingleError) {
try {
throw doris::Exception(ErrorCode::OS_ERROR, "test OS_ERROR {}", "bug");
} catch (doris::Exception& e) {
EXPECT_TRUE(e.to_string().find("OS_ERROR") != std::string::npos);
}
}
TEST_F(ExceptionTest, NestedError) {
try {
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);
}
}
}
} // namespace doris