From 1f986d55889c86969457f9365c55851d05386362 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Tue, 5 Apr 2022 18:17:29 +0200 Subject: [PATCH] Handle assertions as runtime errors --- src/driver/exception.hpp | 12 ++++++++++++ src/driver/std_include.hpp | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/src/driver/exception.hpp b/src/driver/exception.hpp index 7fedb29..e5fb191 100644 --- a/src/driver/exception.hpp +++ b/src/driver/exception.hpp @@ -1,5 +1,17 @@ #pragma once +#ifdef ASSERT +#undef ASSERT +#endif + +#define ASSERT( exp ) if(!(exp)) throw std::runtime_error("Assertion failed: " STRINGIFY(exp)) + +#ifdef NT_ASSERT +#undef NT_ASSERT +#endif + +#define NT_ASSERT( exp ) ASSERT( exp ) + namespace std { class exception diff --git a/src/driver/std_include.hpp b/src/driver/std_include.hpp index e3c7e22..d5a6eba 100644 --- a/src/driver/std_include.hpp +++ b/src/driver/std_include.hpp @@ -8,6 +8,10 @@ #include #pragma warning(pop) +#define STRINGIFY_(a) #a +#define STRINGIFY(a) STRINGIFY_(a) + #include "stdint.hpp" #include "nt_ext.hpp" #include "new.hpp" +#include "exception.hpp"