CBMC
Loading...
Searching...
No Matches
exception_utils.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Exception helper utilities
4
5Author: Fotis Koutoulakis, fotis.koutoulakis@diffblue.com
6
7\*******************************************************************/
8
9#ifndef CPROVER_UTIL_EXCEPTION_UTILS_H
10#define CPROVER_UTIL_EXCEPTION_UTILS_H
11
12#include "invariant.h"
13#include "source_location.h"
14
15#include <sstream>
16#include <string>
17#include <type_traits>
18#include <utility>
19
28{
29public:
33 virtual std::string what() const;
34 virtual ~cprover_exception_baset() = default;
35
37
39
40 // std::ostringstream does not have a copy constructor
45
46 std::string reason() const
47 {
48 return _reason.str();
49 }
50
51protected:
55 explicit cprover_exception_baset(std::string reason)
56 {
57 // ostringstream does not have an appropriate constructor
58 _reason << reason;
59 }
60
64 std::ostringstream _reason;
65
66 // to provide access to the _reason field
67 template <typename E, typename T>
68 friend std::enable_if_t<
69 std::is_base_of<cprover_exception_baset, std::decay_t<E>>::value,
70 E &&>
71 operator<<(E &&, const T &);
72};
73
78template <typename E, typename T>
79std::enable_if_t<
80 std::is_base_of<cprover_exception_baset, std::decay_t<E>>::value,
81 E &&>
82operator<<(E &&e, const T &message)
83{
84 e._reason << message;
85 return std::forward<E>(e);
86}
87
92{
95 std::string option;
97 std::string correct_input;
98
99public:
101 std::string reason,
102 std::string option,
103 std::string correct_input = "");
104
105 std::string what() const override;
106};
107
113{
114public:
115 explicit system_exceptiont(std::string message);
116};
117
121{
122public:
123 explicit deserialization_exceptiont(std::string message);
124};
125
133{
134public:
135 explicit incorrect_goto_program_exceptiont(std::string message);
136
137 template <typename Diagnostic, typename... Diagnostics>
139 std::string message,
140 Diagnostic &&diagnostic,
141 Diagnostics &&... diagnostics);
142
143 template <typename... Diagnostics>
145 std::string message,
147 Diagnostics &&... diagnostics);
148
149 std::string what() const override;
150
151private:
153
154 std::string diagnostics;
155};
156
157template <typename Diagnostic, typename... Diagnostics>
159 std::string message,
160 Diagnostic &&diagnostic,
161 Diagnostics &&... diagnostics)
162 : cprover_exception_baset(std::move(message)),
164 diagnostics(detail::assemble_diagnostics(
165 std::forward<Diagnostic>(diagnostic),
166 std::forward<Diagnostics>(diagnostics)...))
167{
168}
169
170template <typename... Diagnostics>
172 std::string message,
174 Diagnostics &&... diagnostics)
175 : cprover_exception_baset(std::move(message)),
178 detail::assemble_diagnostics(std::forward<Diagnostics>(diagnostics)...))
179{
180}
181
186{
187public:
189 explicit unsupported_operation_exceptiont(std::string message);
190};
191
195{
196public:
197 explicit analysis_exceptiont(std::string reason);
198};
199
204{
205public:
206 explicit invalid_input_exceptiont(std::string reason);
207};
208
213{
214public:
216 std::string reason,
218 std::string what() const override;
219
220 // This method will go away, in favor of cprover_exception_baset::reason
221 std::string get_reason() const
222 {
223 return reason();
224 }
225
227 {
228 return source_location;
229 }
230
231private:
233};
234
235#endif // CPROVER_UTIL_EXCEPTION_UTILS_H
analysis_exceptiont(std::string reason)
std::ostringstream _reason
The reason this exception was generated.
virtual std::string what() const
A human readable description of what went wrong.
friend std::enable_if_t< std::is_base_of< cprover_exception_baset, std::decay_t< E > >::value, E && > operator<<(E &&, const T &)
add to the diagnostic information in the given cprover_exception_baset exception; the type of the exc...
std::string reason() const
cprover_exception_baset(cprover_exception_baset &&)=default
virtual ~cprover_exception_baset()=default
cprover_exception_baset()=default
cprover_exception_baset(std::string reason)
This constructor is marked protected to ensure this class isn't used directly.
Definition c_errors.h:76
std::string reason
The reason this exception was generated.
Definition c_errors.h:83
cprover_exception_baset(const cprover_exception_baset &src)
deserialization_exceptiont(std::string message)
incorrect_goto_program_exceptiont(std::string message)
std::string what() const override
A human readable description of what went wrong.
invalid_command_line_argument_exceptiont(std::string reason, std::string option, std::string correct_input="")
std::string what() const override
A human readable description of what went wrong.
std::string correct_input
In case we have samples of correct input to the option.
std::string option
The full command line option (not the argument) that got erroneous input.
invalid_input_exceptiont(std::string reason)
const source_locationt & get_source_location() const
std::string what() const override
A human readable description of what went wrong.
invalid_source_file_exceptiont(std::string reason, source_locationt source_location)
system_exceptiont(std::string message)
unsupported_operation_exceptiont(std::string message)
message is the unsupported operation causing this fault to occur.
std::enable_if_t< std::is_base_of< cprover_exception_baset, std::decay_t< E > >::value, E && > operator<<(E &&e, const T &message)
add to the diagnostic information in the given cprover_exception_baset exception; the type of the exc...
STL namespace.