aboutsummaryrefslogtreecommitdiff
path: root/zencore/except.cpp
blob: 124b9455fbc27ffb614c7b9cfd9fac230339248c (plain) (blame)
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
// Copyright Epic Games, Inc. All Rights Reserved.

#include <zencore/except.h>
#include <system_error>
#include <fmt/format.h>

namespace zen {

void
ThrowSystemException([[maybe_unused]] HRESULT hRes, [[maybe_unused]] std::string_view Message)
{
	if (HRESULT_FACILITY(hRes) == FACILITY_WIN32)
	{
		throw std::system_error(std::error_code(hRes & 0xffff, std::system_category()), std::string(Message));
	}
	else
	{
		throw WindowsException(hRes, Message);
	}
}

void
ThrowLastError(std::string_view Message)
{
	throw std::system_error(std::error_code(::GetLastError(), std::system_category()), std::string(Message));
}

void
ThrowLastError(std::string_view Message, const std::source_location& Location)
{
	using namespace fmt::literals;
	throw std::system_error(std::error_code(::GetLastError(), std::system_category()), "{}({}): {}"_format(Location.file_name(), Location.line(), Message));
}

}  // namespace zen