From e979447de030d6d942d098914986a175b9b78e77 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Sat, 3 Aug 2024 19:50:26 -0400 Subject: [PATCH] when assertions fail throw an exception instead of aborting --- CMakeLists.txt | 2 +- include/blt/std/assert.h | 2 -- src/blt/std/assert.cpp | 6 +++++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b32288..8828624 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) include(cmake/color.cmake) -set(BLT_VERSION 0.18.17) +set(BLT_VERSION 0.18.18) set(BLT_TEST_VERSION 0.0.1) set(BLT_TARGET BLT) diff --git a/include/blt/std/assert.h b/include/blt/std/assert.h index 0c6f4ef..827fddf 100644 --- a/include/blt/std/assert.h +++ b/include/blt/std/assert.h @@ -35,7 +35,6 @@ namespace blt #define BLT_ASSERT(expr) do { \ if (!static_cast(expr)) { \ blt::b_assert_failed(#expr, nullptr, __FILE__, __LINE__); \ - std::exit(EXIT_FAILURE); \ } \ } while (0) @@ -46,7 +45,6 @@ namespace blt #define BLT_ASSERT_MSG(expr, fail_message) do { \ if (!static_cast(expr)) { \ blt::b_assert_failed(#expr, fail_message, __FILE__, __LINE__); \ - std::exit(EXIT_FAILURE); \ } \ } while (0) diff --git a/src/blt/std/assert.cpp b/src/blt/std/assert.cpp index 2b596e2..4ab9dd2 100644 --- a/src/blt/std/assert.cpp +++ b/src/blt/std/assert.cpp @@ -89,11 +89,15 @@ namespace blt { printStacktrace(messages, size, path, line); BLT_FREE_STACK_TRACE(); -#endif +#else (void) expression; (void) msg; (void) path; (void) line; +#endif + if (msg != nullptr) + throw abort_exception(msg); + throw abort_exception(expression); } void printStacktrace(char** messages, int size, const char* path, int line)