aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/assert.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-09-26 16:44:01 +0000
committerlloyd <[email protected]>2010-09-26 16:44:01 +0000
commitedd522e5ceb31180eed22c2f1bcae50e4f79c2ae (patch)
treee6bbf6742f1eebd68cfc014bd3b220eea450805b /src/utils/assert.cpp
parentecc8ad2244477830c802610016f02a9d5bba8d3e (diff)
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.
Diffstat (limited to 'src/utils/assert.cpp')
-rw-r--r--src/utils/assert.cpp35
1 files changed, 35 insertions, 0 deletions
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 <botan/internal/assert.h>
+#include <botan/exceptn.h>
+#include <sstream>
+
+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());
+ }
+
+}