catch2/include/internal/catch_enforce.cpp
Martin Hořeňovský 1967feac49
Introduce stubs for throwing specific exception types
This allows us to move <stdexcept> out of the common path, and replace
it with just <exception>. The difference between these two headers is
~13k lines after preprocessing on libstdc++ (16k vs 3k) and ~17k lines
for MS's STL(33k vs 16k).

Note that this is only beneficial if no other stdlib header we use
includes <stdexcept>. AFAIK this is true for the newest MS's STL,
but I have no idea of the applicability for libstdc++ and libc++.
2019-06-14 19:13:50 +02:00

41 lines
1.0 KiB
C++

/*
* Created by Martin on 03/09/2018.
*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#include "catch_enforce.h"
#include <stdexcept>
namespace Catch {
#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER)
[[noreturn]]
void throw_exception(std::exception const& e) {
Catch::cerr() << "Catch will terminate because it needed to throw an exception.\n"
<< "The message was: " << e.what() << '\n';
std::terminate();
}
#endif
[[noreturn]]
void throw_logic_error(std::string const& msg) {
throw_exception(std::logic_error(msg));
}
[[noreturn]]
void throw_domain_error(std::string const& msg) {
throw_exception(std::domain_error(msg));
}
[[noreturn]]
void throw_runtime_error(std::string const& msg) {
throw_exception(std::runtime_error(msg));
}
} // namespace Catch;