From e50c0ad976ed0d284b3984e5aa513987af3d32ec Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Wed, 15 Sep 2021 12:32:52 +0200 Subject: Cross-platform zen::GetLastError() --- zencore/except.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'zencore/except.cpp') diff --git a/zencore/except.cpp b/zencore/except.cpp index 9bd447308..609a5387e 100644 --- a/zencore/except.cpp +++ b/zencore/except.cpp @@ -22,13 +22,13 @@ ThrowSystemException([[maybe_unused]] HRESULT hRes, [[maybe_unused]] std::string void ThrowLastError(std::string_view Message) { - throw std::system_error(std::error_code(::GetLastError(), std::system_category()), std::string(Message)); + throw std::system_error(std::error_code(zen::GetLastError(), std::system_category()), std::string(Message)); } std::string GetLastErrorAsString() { - return GetWindowsErrorAsString(::GetLastError()); + return GetWindowsErrorAsString(zen::GetLastError()); } std::string @@ -41,7 +41,7 @@ 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()), + throw std::system_error(std::error_code(zen::GetLastError(), std::system_category()), "{}({}): {}"_format(Location.file_name(), Location.line(), Message)); } -- cgit v1.2.3 From 5558dd1354453edf39c572587b3603f8d08084f4 Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Wed, 15 Sep 2021 12:33:20 +0200 Subject: Moved system_error include to except.h for std::error_code --- zencore/except.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'zencore/except.cpp') diff --git a/zencore/except.cpp b/zencore/except.cpp index 609a5387e..0d31885e1 100644 --- a/zencore/except.cpp +++ b/zencore/except.cpp @@ -2,7 +2,6 @@ #include #include -#include namespace zen { -- cgit v1.2.3 From 38d1bba543e16905576fda7aa0c245fa67ac7372 Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Wed, 15 Sep 2021 12:35:40 +0200 Subject: Added #ifdef condition around Windows-specific exception handling --- zencore/except.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'zencore/except.cpp') diff --git a/zencore/except.cpp b/zencore/except.cpp index 0d31885e1..d57b539cd 100644 --- a/zencore/except.cpp +++ b/zencore/except.cpp @@ -5,6 +5,8 @@ namespace zen { +#if ZEN_PLATFORM_WINDOWS + void ThrowSystemException([[maybe_unused]] HRESULT hRes, [[maybe_unused]] std::string_view Message) { @@ -18,6 +20,8 @@ ThrowSystemException([[maybe_unused]] HRESULT hRes, [[maybe_unused]] std::string } } +#endif // ZEN_PLATFORM_WINDOWS + void ThrowLastError(std::string_view Message) { -- cgit v1.2.3 From 7fa42126867b0c2e87eac035179250bf51a3f5c4 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Wed, 15 Sep 2021 14:56:47 +0200 Subject: Handle absence of std::source_location somewhat more gracefully (relies on client code also checking) --- zencore/except.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'zencore/except.cpp') diff --git a/zencore/except.cpp b/zencore/except.cpp index d57b539cd..834585522 100644 --- a/zencore/except.cpp +++ b/zencore/except.cpp @@ -40,6 +40,7 @@ GetWindowsErrorAsString(uint32_t Win32ErrorCode) return std::error_code(Win32ErrorCode, std::system_category()).message(); } +#if __cpp_lib_source_location void ThrowLastError(std::string_view Message, const std::source_location& Location) { @@ -47,5 +48,6 @@ ThrowLastError(std::string_view Message, const std::source_location& Location) throw std::system_error(std::error_code(zen::GetLastError(), std::system_category()), "{}({}): {}"_format(Location.file_name(), Location.line(), Message)); } +#endif } // namespace zen -- cgit v1.2.3