2017-01-27 12:49:09 -08:00
|
|
|
#include "pch.h"
|
2016-09-18 20:50:08 -07:00
|
|
|
#include "vcpkg_Checks.h"
|
|
|
|
#include "vcpkg_System.h"
|
2017-03-13 16:59:21 -07:00
|
|
|
#include "vcpkglib.h"
|
2016-09-18 20:50:08 -07:00
|
|
|
|
2017-01-05 12:47:08 -08:00
|
|
|
namespace vcpkg::Checks
|
2016-09-18 20:50:08 -07:00
|
|
|
{
|
2017-03-13 16:59:21 -07:00
|
|
|
__declspec(noreturn) void unreachable(const LineInfo& line_info)
|
2016-09-18 20:50:08 -07:00
|
|
|
{
|
|
|
|
System::println(System::color::error, "Error: Unreachable code was reached");
|
2017-03-13 16:59:21 -07:00
|
|
|
System::println(System::color::error, line_info.toString()); // Always print line_info here
|
2016-11-05 01:02:15 -07:00
|
|
|
#ifndef NDEBUG
|
|
|
|
std::abort();
|
2016-11-15 17:54:44 -08:00
|
|
|
#else
|
2016-09-18 20:50:08 -07:00
|
|
|
exit(EXIT_FAILURE);
|
2016-11-15 17:54:44 -08:00
|
|
|
#endif
|
2016-09-18 20:50:08 -07:00
|
|
|
}
|
|
|
|
|
2017-03-02 18:52:15 -08:00
|
|
|
__declspec(noreturn) void exit_with_message(const char* errorMessage)
|
2016-09-18 20:50:08 -07:00
|
|
|
{
|
|
|
|
System::println(System::color::error, errorMessage);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2017-03-02 18:52:15 -08:00
|
|
|
__declspec(noreturn) void throw_with_message(const char* errorMessage)
|
2016-09-18 20:50:08 -07:00
|
|
|
{
|
|
|
|
throw std::runtime_error(errorMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
void check_throw(bool expression, const char* errorMessage)
|
|
|
|
{
|
|
|
|
if (!expression)
|
|
|
|
{
|
|
|
|
throw_with_message(errorMessage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-10 16:51:36 -08:00
|
|
|
void check_exit(bool expression)
|
|
|
|
{
|
|
|
|
if (!expression)
|
|
|
|
{
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-18 20:50:08 -07:00
|
|
|
void check_exit(bool expression, const char* errorMessage)
|
|
|
|
{
|
|
|
|
if (!expression)
|
|
|
|
{
|
2016-09-29 14:31:28 -07:00
|
|
|
exit_with_message(errorMessage);
|
2016-09-18 20:50:08 -07:00
|
|
|
}
|
|
|
|
}
|
2017-01-05 12:47:08 -08:00
|
|
|
}
|