1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#include "pch.h"
#include "vcpkg_Checks.h"
#include "vcpkg_System.h"
#include "vcpkglib.h"
namespace vcpkg::Checks
{
static void print_line_info_if_debug(const LineInfo& line_info)
{
if (g_debugging)
{
System::println(System::color::error, line_info.toString());
}
}
__declspec(noreturn) void unreachable(const LineInfo& line_info)
{
System::println(System::color::error, "Error: Unreachable code was reached");
System::println(System::color::error, line_info.toString()); // Always print line_info here
#ifndef NDEBUG
std::abort();
#else
::exit(EXIT_FAILURE);
#endif
}
void exit_with_code(const LineInfo& line_info, const int exit_code)
{
print_line_info_if_debug(line_info);
::exit(exit_code);
}
__declspec(noreturn) void exit_with_message(const LineInfo& line_info, const cstring_view errorMessage)
{
System::println(System::color::error, errorMessage);
exit_fail(line_info);
}
__declspec(noreturn) void throw_with_message(const LineInfo& line_info, const cstring_view errorMessage)
{
print_line_info_if_debug(line_info);
throw std::runtime_error(errorMessage);
}
void check_throw(const LineInfo& line_info, bool expression, const cstring_view errorMessage)
{
if (!expression)
{
throw_with_message(line_info, errorMessage);
}
}
void check_exit(const LineInfo& line_info, bool expression)
{
if (!expression)
{
exit_with_message(line_info, "");
}
}
void check_exit(const LineInfo& line_info, bool expression, const cstring_view errorMessage)
{
if (!expression)
{
exit_with_message(line_info, errorMessage);
}
}
}
|