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 
throw_invalid_argument(const char * message,const char * func,const char * file)13 void throw_invalid_argument(const char* message,
14                             const char* func,
15                             const char* file)
16    {
17    std::ostringstream format;
18    format << message << " in " << func << ":" << file;
19    throw Invalid_Argument(format.str());
20    }
21 
throw_invalid_state(const char * expr,const char * func,const char * file)22 void throw_invalid_state(const char* expr,
23                          const char* func,
24                          const char* file)
25    {
26    std::ostringstream format;
27    format << "Invalid state: " << expr << " was false in " << func << ":" << file;
28    throw Invalid_State(format.str());
29    }
30 
assertion_failure(const char * expr_str,const char * assertion_made,const char * func,const char * file,int line)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    {
37    std::ostringstream format;
38 
39    format << "False assertion ";
40 
41    if(assertion_made && assertion_made[0] != 0)
42       format << "'" << assertion_made << "' (expression " << expr_str << ") ";
43    else
44       format << expr_str << " ";
45 
46    if(func)
47       format << "in " << func << " ";
48 
49    format << "@" << file << ":" << line;
50 
51    throw Internal_Error(format.str());
52    }
53 
54 }
55