From edd522e5ceb31180eed22c2f1bcae50e4f79c2ae Mon Sep 17 00:00:00 2001 From: lloyd Date: Sun, 26 Sep 2010 16:44:01 +0000 Subject: There is a pretty common pattern in the code for testing for internal errors of the form if(some_expr_indicating_failure) throw Internal_Error("Some mildly informative message"); Make this simpiler with the addition of a BOTAN_ASSERT macro which will throw an exception upon failure. --- src/utils/assert.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/utils/assert.cpp (limited to 'src/utils/assert.cpp') diff --git a/src/utils/assert.cpp b/src/utils/assert.cpp new file mode 100644 index 000000000..29af831d8 --- /dev/null +++ b/src/utils/assert.cpp @@ -0,0 +1,35 @@ +/* +* Runtime assertion checking +* (C) 2010 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include +#include +#include + +namespace Botan { + +void assertion_failure(const char* expr_str, + const char* msg, + const char* func, + const char* file, + int line) + { + std::ostringstream format; + + format << "Assertion " << expr_str << " failed "; + + if(msg) + format << "(" << msg << ") "; + + if(func) + format << "in " << func << " "; + + format << "@" << file << ":" << line; + + throw Internal_Error(format.str()); + } + +} -- cgit v1.2.3