Skip to content

Commit 8b5b51d

Browse files
authored
Merge pull request #3190 from hannes-steffenhagen-diffblue/invariant_cleanup-initialize_goto_model
Use structured exceptions in initialize_goto_model
2 parents 8321a10 + eed0bdc commit 8b5b51d

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

src/goto-programs/initialize_goto_model.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Author: Daniel Kroening, [email protected]
2323
#include <langapi/language.h>
2424

2525
#include <goto-programs/rebuild_goto_start_function.h>
26+
#include <util/exception_utils.h>
2627

2728
#include "goto_convert_functions.h"
2829
#include "read_goto_binary.h"
@@ -36,8 +37,10 @@ goto_modelt initialize_goto_model(
3637
const std::vector<std::string> &files=cmdline.args;
3738
if(files.empty())
3839
{
39-
msg.error() << "Please provide a program" << messaget::eom;
40-
throw 0;
40+
throw invalid_command_line_argument_exceptiont(
41+
"missing program argument",
42+
"filename",
43+
"one or more paths to program files");
4144
}
4245

4346
std::vector<std::string> binaries, sources;
@@ -69,21 +72,17 @@ goto_modelt initialize_goto_model(
6972

7073
if(!infile)
7174
{
72-
msg.error() << "failed to open input file `" << filename
73-
<< '\'' << messaget::eom;
74-
throw 0;
75+
throw system_exceptiont(
76+
"Failed to open input file `" + filename + '\'');
7577
}
7678

7779
language_filet &lf=language_files.add_file(filename);
7880
lf.language=get_language_from_filename(filename);
7981

8082
if(lf.language==nullptr)
8183
{
82-
source_locationt location;
83-
location.set_file(filename);
84-
msg.error().source_location=location;
85-
msg.error() << "failed to figure out type of file" << messaget::eom;
86-
throw 0;
84+
throw invalid_source_file_exceptiont(
85+
"Failed to figure out type of file `" + filename + '\'');
8786
}
8887

8988
languaget &language=*lf.language;
@@ -94,8 +93,7 @@ goto_modelt initialize_goto_model(
9493

9594
if(language.parse(infile, filename))
9695
{
97-
msg.error() << "PARSING ERROR" << messaget::eom;
98-
throw 0;
96+
throw invalid_source_file_exceptiont("PARSING ERROR");
9997
}
10098

10199
lf.get_modules();
@@ -105,8 +103,7 @@ goto_modelt initialize_goto_model(
105103

106104
if(language_files.typecheck(goto_model.symbol_table))
107105
{
108-
msg.error() << "CONVERSION ERROR" << messaget::eom;
109-
throw 0;
106+
throw invalid_source_file_exceptiont("CONVERSION ERROR");
110107
}
111108
}
112109

@@ -115,7 +112,10 @@ goto_modelt initialize_goto_model(
115112
msg.status() << "Reading GOTO program from file" << messaget::eom;
116113

117114
if(read_object_and_link(file, goto_model, message_handler))
118-
throw 0;
115+
{
116+
throw invalid_source_file_exceptiont(
117+
"failed to read object or link in file `" + file + '\'');
118+
}
119119
}
120120

121121
bool binaries_provided_start=
@@ -150,14 +150,12 @@ goto_modelt initialize_goto_model(
150150

151151
if(entry_point_generation_failed)
152152
{
153-
msg.error() << "SUPPORT FUNCTION GENERATION ERROR" << messaget::eom;
154-
throw 0;
153+
throw invalid_source_file_exceptiont("SUPPORT FUNCTION GENERATION ERROR");
155154
}
156155

157156
if(language_files.final(goto_model.symbol_table))
158157
{
159-
msg.error() << "FINAL STAGE CONVERSION ERROR" << messaget::eom;
160-
throw 0;
158+
throw invalid_source_file_exceptiont("FINAL STAGE CONVERSION ERROR");
161159
}
162160

163161
msg.status() << "Generating GOTO Program" << messaget::eom;

0 commit comments

Comments
 (0)