Botan 3.0.0
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/internal/fmt.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 throw Invalid_Argument(fmt("{} in {}:{}", message, func, file));
24 }
25
26void throw_invalid_state(const char* expr,
27 const char* func,
28 const char* file)
29 {
30 throw Invalid_State(fmt("Invalid state: expr {} was false in {}:{}", expr, func, file));
31 }
32
33void assertion_failure(const char* expr_str,
34 const char* assertion_made,
35 const char* func,
36 const char* file,
37 int line)
38 {
39 std::ostringstream format;
40
41 format << "False assertion ";
42
43 if(assertion_made && assertion_made[0] != 0)
44 format << "'" << assertion_made << "' (expression " << expr_str << ") ";
45 else
46 format << expr_str << " ";
47
48 if(func)
49 format << "in " << func << " ";
50
51 format << "@" << file << ":" << line;
52
53#if defined(BOTAN_TERMINATE_ON_ASSERTS)
54 std::cerr << format.str() << '\n';
55 std::abort();
56#else
57 throw Internal_Error(format.str());
58#endif
59 }
60
61}
Definition: alg_id.cpp:12
void throw_invalid_state(const char *expr, const char *func, const char *file)
Definition: assert.cpp:26
void throw_invalid_argument(const char *message, const char *func, const char *file)
Definition: assert.cpp:19
std::string fmt(std::string_view format, const T &... args)
Definition: fmt.h:60
void assertion_failure(const char *expr_str, const char *assertion_made, const char *func, const char *file, int line)
Definition: assert.cpp:33