aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/except.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-05-23 10:47:28 +0200
committerGitHub <[email protected]>2023-05-23 10:47:28 +0200
commit45aad3d98ee23e7f0e5873962a55c15a53d6b5c7 (patch)
tree8fbf9907a934c69aeea3e2fdf16802ae4b8c9ad0 /src/zencore/except.cpp
parentstreaming decompression support (#142) (diff)
downloadzen-45aad3d98ee23e7f0e5873962a55c15a53d6b5c7.tar.xz
zen-45aad3d98ee23e7f0e5873962a55c15a53d6b5c7.zip
use exception when allocations fail rather than asserts (#319)
* use exception when allocations fail rather than asserts * changelog
Diffstat (limited to 'src/zencore/except.cpp')
-rw-r--r--src/zencore/except.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/zencore/except.cpp b/src/zencore/except.cpp
index 2749d1984..65f5ebc62 100644
--- a/src/zencore/except.cpp
+++ b/src/zencore/except.cpp
@@ -90,4 +90,24 @@ ThrowLastError(std::string_view Message)
}
#endif
+#if ZEN_PLATFORM_WINDOWS
+static const std::error_code OutOfMemoryErrorCode(ERROR_NOT_ENOUGH_MEMORY, std::system_category());
+#else
+static const std::error_code OutOfMemoryErrorCode(ENOMEM, std::system_category());
+#endif
+
+#if defined(__cpp_lib_source_location)
+void
+ThrowOutOfMemoryImpl(std::string_view Message, const std::source_location& Location)
+{
+ throw std::system_error(OutOfMemoryErrorCode, fmt::format("{}({}): {}", Location.file_name(), Location.line(), Message));
+}
+#else
+void
+ThrowOutOfMemory(std::string_view Message)
+{
+ throw std::system_error(OutOfMemoryErrorCode, std::string(Message));
+}
+#endif
+
} // namespace zen