错误处理

This commit is contained in:
2026-08-16 18:33:24 +08:00
parent 8612b5ff86
commit 389ff81d42
44 changed files with 536 additions and 261 deletions
@@ -0,0 +1,35 @@
#include <renderive/error/Error_Policy.hpp>
#include <gtest/gtest.h>
#include <stdexcept>
namespace renderive::error {
namespace {
TEST(ErrorPolicy, ExceptionModePreservesExceptionType) {
set_mode(Mode::exception);
EXPECT_THROW(unexpected<std::invalid_argument>("invalid value"),
std::invalid_argument);
}
TEST(ErrorPolicy, FastFailModeTerminatesAtThePolicyBoundary) {
EXPECT_DEATH(
{
set_mode(Mode::fast_fail);
unexpected<std::logic_error>("broken invariant");
},
"broken invariant");
}
TEST(ErrorPolicy, CaptureUsesTheSameMode) {
set_mode(Mode::exception);
const auto exception = capture<std::logic_error>("async failure");
ASSERT_TRUE(exception);
EXPECT_THROW(std::rethrow_exception(exception), std::logic_error);
}
} // namespace
} // namespace renderive::error