File indexing completed on 2025-01-30 10:02:49
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef CATCH_ENFORCE_HPP_INCLUDED
0009 #define CATCH_ENFORCE_HPP_INCLUDED
0010
0011 #include <catch2/internal/catch_source_line_info.hpp>
0012 #include <catch2/internal/catch_compiler_capabilities.hpp>
0013 #include <catch2/internal/catch_reusable_string_stream.hpp>
0014
0015 #include <exception>
0016
0017 namespace Catch {
0018 #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
0019 template <typename Ex>
0020 [[noreturn]]
0021 void throw_exception(Ex const& e) {
0022 throw e;
0023 }
0024 #else
0025 [[noreturn]]
0026 void throw_exception(std::exception const& e);
0027 #endif
0028
0029 [[noreturn]]
0030 void throw_logic_error(std::string const& msg);
0031 [[noreturn]]
0032 void throw_domain_error(std::string const& msg);
0033 [[noreturn]]
0034 void throw_runtime_error(std::string const& msg);
0035
0036 }
0037
0038 #define CATCH_MAKE_MSG(...) \
0039 (Catch::ReusableStringStream() << __VA_ARGS__).str()
0040
0041 #define CATCH_INTERNAL_ERROR(...) \
0042 Catch::throw_logic_error(CATCH_MAKE_MSG( CATCH_INTERNAL_LINEINFO << ": Internal Catch2 error: " << __VA_ARGS__))
0043
0044 #define CATCH_ERROR(...) \
0045 Catch::throw_domain_error(CATCH_MAKE_MSG( __VA_ARGS__ ))
0046
0047 #define CATCH_RUNTIME_ERROR(...) \
0048 Catch::throw_runtime_error(CATCH_MAKE_MSG( __VA_ARGS__ ))
0049
0050 #define CATCH_ENFORCE( condition, ... ) \
0051 do{ if( !(condition) ) CATCH_ERROR( __VA_ARGS__ ); } while(false)
0052
0053
0054 #endif