catch_enforce.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Created by Martin on 03/09/2018.
  3. *
  4. * Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #include "catch_enforce.h"
  8. #include <stdexcept>
  9. namespace Catch {
  10. #if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER)
  11. [[noreturn]]
  12. void throw_exception(std::exception const& e) {
  13. Catch::cerr() << "Catch will terminate because it needed to throw an exception.\n"
  14. << "The message was: " << e.what() << '\n';
  15. std::terminate();
  16. }
  17. #endif
  18. [[noreturn]]
  19. void throw_logic_error(std::string const& msg) {
  20. throw_exception(std::logic_error(msg));
  21. }
  22. [[noreturn]]
  23. void throw_domain_error(std::string const& msg) {
  24. throw_exception(std::domain_error(msg));
  25. }
  26. [[noreturn]]
  27. void throw_runtime_error(std::string const& msg) {
  28. throw_exception(std::runtime_error(msg));
  29. }
  30. } // namespace Catch;