aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-08-09 14:12:59 +0200
committerStefan Boberg <[email protected]>2021-08-09 14:12:59 +0200
commitdcadd5a52dadb244d93167dca94a747ed42e2f08 (patch)
tree801b5ae986e6c1dc64de20346d9db288aaf3e7ff
parentAdded IsProcessRunning()/GetCurrentProcessId() helpers (diff)
downloadzen-dcadd5a52dadb244d93167dca94a747ed42e2f08.tar.xz
zen-dcadd5a52dadb244d93167dca94a747ed42e2f08.zip
Added ThrowLastError which accepts a std::source_location
-rw-r--r--zencore/except.cpp8
-rw-r--r--zencore/include/zencore/except.h3
2 files changed, 11 insertions, 0 deletions
diff --git a/zencore/except.cpp b/zencore/except.cpp
index 882f69f9a..124b9455f 100644
--- a/zencore/except.cpp
+++ b/zencore/except.cpp
@@ -2,6 +2,7 @@
#include <zencore/except.h>
#include <system_error>
+#include <fmt/format.h>
namespace zen {
@@ -24,4 +25,11 @@ 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
diff --git a/zencore/include/zencore/except.h b/zencore/include/zencore/except.h
index 782dbeed0..2357ba1b5 100644
--- a/zencore/include/zencore/except.h
+++ b/zencore/include/zencore/except.h
@@ -4,6 +4,7 @@
#include <zencore/string.h>
#include <zencore/windows.h>
+#include <source_location>
#include <string>
namespace zen {
@@ -52,5 +53,7 @@ ThrowSystemException(const char* Message)
}
ZENCORE_API void ThrowLastError(std::string_view Message);
+ZENCORE_API void ThrowLastError(std::string_view Message, const std::source_location& Location);
+
} // namespace zen