Botan  2.4.0
Crypto and TLS for C++11
exceptn.h
Go to the documentation of this file.
1 /*
2 * Exceptions
3 * (C) 1999-2009 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_EXCEPTION_H_
9 #define BOTAN_EXCEPTION_H_
10 
11 #include <botan/types.h>
12 #include <exception>
13 #include <string>
14 
15 namespace Botan {
16 
17 /**
18 * Base class for all exceptions thrown by the library
19 */
20 class BOTAN_PUBLIC_API(2,0) Exception : public std::exception
21  {
22  public:
23  Exception(const char* prefix, const std::string& msg);
24  explicit Exception(const std::string& msg);
25  const char* what() const BOTAN_NOEXCEPT override { return m_msg.c_str(); }
26  private:
27  std::string m_msg;
28  };
29 
30 /**
31 * An invalid argument
32 */
34  {
35  public:
36  explicit Invalid_Argument(const std::string& msg);
37 
38  explicit Invalid_Argument(const std::string& msg, const std::string& where);
39 };
40 
41 #define BOTAN_ARG_CHECK(expr) \
42  do { if(!(expr)) throw Invalid_Argument(#expr, BOTAN_CURRENT_FUNCTION); } while(0)
43 
44 /**
45 * Unsupported_Argument Exception
46 *
47 * An argument that is invalid because it is not supported by Botan.
48 * It might or might not be valid in another context like a standard.
49 */
51  {
52  public:
53  explicit Unsupported_Argument(const std::string& msg) : Invalid_Argument(msg) {}
54  };
55 
56 /**
57 * Invalid_State Exception
58 */
60  {
61  public:
62  explicit Invalid_State(const std::string& err) : Exception(err) {}
63  };
64 
66  {
67  public:
68  explicit Key_Not_Set(const std::string& algo);
69  };
70 
71 /**
72 * Lookup_Error Exception
73 */
75  {
76  public:
77  explicit Lookup_Error(const std::string& err) : Exception(err) {}
78 
79  Lookup_Error(const std::string& type,
80  const std::string& algo,
81  const std::string& provider);
82  };
83 
84 /**
85 * Internal_Error Exception
86 */
88  {
89  public:
90  explicit Internal_Error(const std::string& err);
91  };
92 
93 /**
94 * Invalid_Key_Length Exception
95 */
97  {
98  public:
99  Invalid_Key_Length(const std::string& name, size_t length);
100  };
101 
102 /**
103 * Invalid_IV_Length Exception
104 */
106  {
107  public:
108  Invalid_IV_Length(const std::string& mode, size_t bad_len);
109  };
110 
111 /**
112 * PRNG_Unseeded Exception
113 */
115  {
116  public:
117  explicit PRNG_Unseeded(const std::string& algo);
118  };
119 
120 /**
121 * Policy_Violation Exception
122 */
124  {
125  public:
126  BOTAN_DEPRECATED("deprecated") explicit Policy_Violation(const std::string& err);
127  };
128 
129 /**
130 * Algorithm_Not_Found Exception
131 */
133  {
134  public:
135  explicit Algorithm_Not_Found(const std::string& name);
136  };
137 
138 /**
139 * No_Provider_Found Exception
140 */
142  {
143  public:
144  BOTAN_DEPRECATED("deprecated") explicit No_Provider_Found(const std::string& name);
145  };
146 
147 /**
148 * Provider_Not_Found is thrown when a specific provider was requested
149 * but that provider is not available.
150 */
152  {
153  public:
154  Provider_Not_Found(const std::string& algo, const std::string& provider);
155  };
156 
157 /**
158 * Invalid_Algorithm_Name Exception
159 */
161  {
162  public:
163  explicit Invalid_Algorithm_Name(const std::string& name);
164  };
165 
166 /**
167 * Encoding_Error Exception
168 */
170  {
171  public:
172  explicit Encoding_Error(const std::string& name);
173  };
174 
175 /**
176 * Decoding_Error Exception
177 */
179  {
180  public:
181  explicit Decoding_Error(const std::string& name);
182 
183  Decoding_Error(const std::string& name, const char* exception_message);
184  };
185 
186 /**
187 * Integrity_Failure Exception
188 */
190  {
191  public:
192  explicit Integrity_Failure(const std::string& msg);
193  };
194 
195 /**
196 * Invalid_OID Exception
197 */
198 class BOTAN_PUBLIC_API(2,0) Invalid_OID final : public Decoding_Error
199  {
200  public:
201  explicit Invalid_OID(const std::string& oid);
202  };
203 
204 /**
205 * Stream_IO_Error Exception
206 */
207 class BOTAN_PUBLIC_API(2,0) Stream_IO_Error final : public Exception
208  {
209  public:
210  explicit Stream_IO_Error(const std::string& err);
211  };
212 
213 /**
214 * Self Test Failure Exception
215 */
217  {
218  public:
219  BOTAN_DEPRECATED("deprecated") explicit Self_Test_Failure(const std::string& err);
220  };
221 
222 /**
223 * Not Implemented Exception
224 */
225 class BOTAN_PUBLIC_API(2,0) Not_Implemented final : public Exception
226  {
227  public:
228  explicit Not_Implemented(const std::string& err);
229  };
230 
231 }
232 
233 #endif
Invalid_State(const std::string &err)
Definition: exceptn.h:62
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
MechanismType type
#define BOTAN_NOEXCEPT
Definition: compiler.h:154
Unsupported_Argument(const std::string &msg)
Definition: exceptn.h:53
const char * what() const BOTAN_NOEXCEPT override
Definition: exceptn.h:25
Definition: alg_id.cpp:13
Lookup_Error(const std::string &err)
Definition: exceptn.h:77