Botan 3.0.0-alpha0
Crypto and TLS for C&
assert.cpp
Go to the documentation of this file.
1/*
2* Runtime assertion checking
3* (C) 2010,2012,2018 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#include <botan/exceptn.h>
9#include <botan/build.h>
10#include <sstream>
11
12#if defined(BOTAN_TERMINATE_ON_ASSERTS)
13 #include <cstdlib>
14 #include <iostream>
15#endif
16
17namespace Botan {
18
19void throw_invalid_argument(const char* message,
20 const char* func,
21 const char* file)
22 {
23 std::ostringstream format;
24 format << message << " in " << func << ":" << file;
25 throw Invalid_Argument(format.str());
26 }
27
28void throw_invalid_state(const char* expr,
29 const char* func,
30 const char* file)
31 {
32 std::ostringstream format;
33 format << "Invalid state: " << expr << " was false in " << func << ":" << file;
34 throw Invalid_State(format.str());
35 }
36
37void assertion_failure(const char* expr_str,
38 const char* assertion_made,
39 const char* func,
40 const char* file,
41 int line)
42 {
43 std::ostringstream format;
44
45 format << "False assertion ";
46
47 if(assertion_made && assertion_made[0] != 0)
48 format << "'" << assertion_made << "' (expression " << expr_str << ") ";
49 else
50 format << expr_str << " ";
51
52 if(func)
53 format << "in " << func << " ";
54
55 format << "@" << file << ":" << line;
56
57#if defined(BOTAN_TERMINATE_ON_ASSERTS)
58 std::cerr << format.str() << '\n';
59 std::abort();
60#else
61 throw Internal_Error(format.str());
62#endif
63 }
64
65}
Definition: alg_id.cpp:13
void throw_invalid_state(const char *expr, const char *func, const char *file)
Definition: assert.cpp:28
void throw_invalid_argument(const char *message, const char *func, const char *file)
Definition: assert.cpp:19
void assertion_failure(const char *expr_str, const char *assertion_made, const char *func, const char *file, int line)
Definition: assert.cpp:37