vcpkg/toolsrc/src/vcpkg_Checks.cpp

52 lines
1.0 KiB
C++
Raw Normal View History

2017-01-28 04:49:09 +08:00
#include "pch.h"
2016-09-19 11:50:08 +08:00
#include "vcpkg_Checks.h"
#include "vcpkg_System.h"
2017-01-06 04:47:08 +08:00
namespace vcpkg::Checks
2016-09-19 11:50:08 +08:00
{
void unreachable()
{
System::println(System::color::error, "Error: Unreachable code was reached");
#ifndef NDEBUG
std::abort();
2016-11-16 09:54:44 +08:00
#else
2016-09-19 11:50:08 +08:00
exit(EXIT_FAILURE);
2016-11-16 09:54:44 +08:00
#endif
2016-09-19 11:50:08 +08:00
}
void exit_with_message(const char* errorMessage)
{
System::println(System::color::error, errorMessage);
exit(EXIT_FAILURE);
}
void throw_with_message(const char* errorMessage)
{
throw std::runtime_error(errorMessage);
}
void check_throw(bool expression, const char* errorMessage)
{
if (!expression)
{
throw_with_message(errorMessage);
}
}
void check_exit(bool expression)
{
if (!expression)
{
exit(EXIT_FAILURE);
}
}
2016-09-19 11:50:08 +08:00
void check_exit(bool expression, const char* errorMessage)
{
if (!expression)
{
exit_with_message(errorMessage);
2016-09-19 11:50:08 +08:00
}
}
2017-01-06 04:47:08 +08:00
}