@@ -27,17 +27,28 @@ class cprover_exception_baset
2727 // / A human readable description of what went wrong.
2828 // / For readability, implementors should not add a leading
2929 // / or trailing newline to this description.
30- virtual std::string what () const = 0 ;
30+ virtual std::string what () const ;
3131 virtual ~cprover_exception_baset () = default ;
32+
33+ protected:
34+ // / This constructor is marked protected to ensure this class isn't used
35+ // / directly. Deriving classes should be used to more precisely describe the
36+ // / problem that occurred.
37+ explicit cprover_exception_baset (std::string reason)
38+ : reason(std::move(reason))
39+ {
40+ }
41+
42+ // / The reason this exception was generated. This is the string returned by
43+ // / `what()` unless that method is overridden
44+ std::string reason;
3245};
3346
3447// / Thrown when users pass incorrect command line arguments,
3548// / for example passing no files to analysis or setting
3649// / two mutually exclusive flags
3750class invalid_command_line_argument_exceptiont : public cprover_exception_baset
3851{
39- // / The reason this exception was generated.
40- std::string reason;
4152 // / The full command line option (not the argument) that got
4253 // / erroneous input.
4354 std::string option;
@@ -61,10 +72,6 @@ class system_exceptiont : public cprover_exception_baset
6172{
6273public:
6374 explicit system_exceptiont (std::string message);
64- std::string what () const override ;
65-
66- private:
67- std::string message;
6875};
6976
7077// / Thrown when failing to deserialize a value from some
@@ -73,11 +80,6 @@ class deserialization_exceptiont : public cprover_exception_baset
7380{
7481public:
7582 explicit deserialization_exceptiont (std::string message);
76-
77- std::string what () const override ;
78-
79- private:
80- std::string message;
8183};
8284
8385// / Thrown when a goto program that's being processed is in an invalid format,
@@ -106,7 +108,6 @@ class incorrect_goto_program_exceptiont : public cprover_exception_baset
106108 std::string what () const override ;
107109
108110private:
109- std::string message;
110111 source_locationt source_location;
111112
112113 std::string diagnostics;
@@ -117,8 +118,8 @@ incorrect_goto_program_exceptiont::incorrect_goto_program_exceptiont(
117118 std::string message,
118119 Diagnostic &&diagnostic,
119120 Diagnostics &&... diagnostics)
120- : message (std::move(message)),
121- source_location(),
121+ : cprover_exception_baset (std::move(message)),
122+ source_location(source_locationt::nil() ),
122123 diagnostics(detail::assemble_diagnostics(
123124 std::forward<Diagnostic>(diagnostic),
124125 std::forward<Diagnostics>(diagnostics)...))
@@ -130,7 +131,7 @@ incorrect_goto_program_exceptiont::incorrect_goto_program_exceptiont(
130131 std::string message,
131132 source_locationt source_location,
132133 Diagnostics &&... diagnostics)
133- : message (std::move(message)),
134+ : cprover_exception_baset (std::move(message)),
134135 source_location(std::move(source_location)),
135136 diagnostics(
136137 detail::assemble_diagnostics (std::forward<Diagnostics>(diagnostics)...))
@@ -143,12 +144,8 @@ incorrect_goto_program_exceptiont::incorrect_goto_program_exceptiont(
143144class unsupported_operation_exceptiont : public cprover_exception_baset
144145{
145146public:
147+ // / \p message is the unsupported operation causing this fault to occur.
146148 explicit unsupported_operation_exceptiont (std::string message);
147- std::string what () const override ;
148-
149- private:
150- // / The unsupported operation causing this fault to occur.
151- std::string message;
152149};
153150
154151// / Thrown when an unexpected error occurs during the analysis (e.g., when the
@@ -157,11 +154,6 @@ class analysis_exceptiont : public cprover_exception_baset
157154{
158155public:
159156 explicit analysis_exceptiont (std::string reason);
160- std::string what () const override ;
161-
162- private:
163- // / The reason this exception was generated.
164- std::string reason;
165157};
166158
167159// / Thrown when we can't handle something in an input source file.
@@ -171,10 +163,6 @@ class invalid_source_file_exceptiont : public cprover_exception_baset
171163{
172164public:
173165 explicit invalid_source_file_exceptiont (std::string reason);
174- std::string what () const override ;
175-
176- private:
177- std::string reason;
178166};
179167
180168#endif // CPROVER_UTIL_EXCEPTION_UTILS_H
0 commit comments