/src/botan/src/lib/utils/assert.cpp
Line | Count | Source (jump to first uncovered line) |
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 <sstream> |
10 | | |
11 | | namespace Botan { |
12 | | |
13 | | void throw_invalid_argument(const char* message, |
14 | | const char* func, |
15 | | const char* file) |
16 | 1.02k | { |
17 | 1.02k | std::ostringstream format; |
18 | 1.02k | format << message << " in " << func << ":" << file; |
19 | 1.02k | throw Invalid_Argument(format.str()); |
20 | 1.02k | } |
21 | | |
22 | | void throw_invalid_state(const char* expr, |
23 | | const char* func, |
24 | | const char* file) |
25 | 0 | { |
26 | 0 | std::ostringstream format; |
27 | 0 | format << "Invalid state: " << expr << " was false in " << func << ":" << file; |
28 | 0 | throw Invalid_State(format.str()); |
29 | 0 | } |
30 | | |
31 | | void assertion_failure(const char* expr_str, |
32 | | const char* assertion_made, |
33 | | const char* func, |
34 | | const char* file, |
35 | | int line) |
36 | 816 | { |
37 | 816 | std::ostringstream format; |
38 | | |
39 | 816 | format << "False assertion "; |
40 | | |
41 | 816 | if(assertion_made && assertion_made[0] != 0) |
42 | 809 | format << "'" << assertion_made << "' (expression " << expr_str << ") "; |
43 | 7 | else |
44 | 7 | format << expr_str << " "; |
45 | | |
46 | 816 | if(func) |
47 | 816 | format << "in " << func << " "; |
48 | | |
49 | 816 | format << "@" << file << ":" << line; |
50 | | |
51 | 816 | throw Internal_Error(format.str()); |
52 | 816 | } |
53 | | |
54 | | } |