Skip to content

Commit 9d607ce

Browse files
Use structured exceptions in initialize_goto_model
1 parent 49230ec commit 9d607ce

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/goto-programs/initialize_goto_model.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <utility>
2+
13
/*******************************************************************\
24
35
Module: Get a Goto Program
@@ -23,6 +25,7 @@ Author: Daniel Kroening, [email protected]
2325
#include <langapi/language.h>
2426

2527
#include <goto-programs/rebuild_goto_start_function.h>
28+
#include <util/exception_utils.h>
2629

2730
#include "goto_convert_functions.h"
2831
#include "read_goto_binary.h"
@@ -36,8 +39,10 @@ goto_modelt initialize_goto_model(
3639
const std::vector<std::string> &files=cmdline.args;
3740
if(files.empty())
3841
{
39-
msg.error() << "Please provide a program" << messaget::eom;
40-
throw 0;
42+
throw invalid_command_line_argument_exceptiont(
43+
"missing program argument",
44+
"filename",
45+
"one or more paths to program files");
4146
}
4247

4348
std::vector<std::string> binaries, sources;
@@ -69,21 +74,17 @@ goto_modelt initialize_goto_model(
6974

7075
if(!infile)
7176
{
72-
msg.error() << "failed to open input file `" << filename
73-
<< '\'' << messaget::eom;
74-
throw 0;
77+
throw system_exceptiont(
78+
"Failed to open input file `" + filename + '\'');
7579
}
7680

7781
language_filet &lf=language_files.add_file(filename);
7882
lf.language=get_language_from_filename(filename);
7983

8084
if(lf.language==nullptr)
8185
{
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;
86+
throw invalid_source_file_exceptiont(
87+
"Failed to figure out type of file `" + filename + '\'');
8788
}
8889

8990
languaget &language=*lf.language;
@@ -94,8 +95,7 @@ goto_modelt initialize_goto_model(
9495

9596
if(language.parse(infile, filename))
9697
{
97-
msg.error() << "PARSING ERROR" << messaget::eom;
98-
throw 0;
98+
throw invalid_source_file_exceptiont("PARSING ERROR");
9999
}
100100

101101
lf.get_modules();
@@ -105,8 +105,7 @@ goto_modelt initialize_goto_model(
105105

106106
if(language_files.typecheck(goto_model.symbol_table))
107107
{
108-
msg.error() << "CONVERSION ERROR" << messaget::eom;
109-
throw 0;
108+
throw invalid_source_file_exceptiont("CONVERSION ERROR");
110109
}
111110
}
112111

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

117116
if(read_object_and_link(file, goto_model, message_handler))
118-
throw 0;
117+
{
118+
throw invalid_source_file_exceptiont(
119+
"failed to read object or link in file `" + file + '\'');
120+
}
119121
}
120122

121123
bool binaries_provided_start=
@@ -150,14 +152,12 @@ goto_modelt initialize_goto_model(
150152

151153
if(entry_point_generation_failed)
152154
{
153-
msg.error() << "SUPPORT FUNCTION GENERATION ERROR" << messaget::eom;
154-
throw 0;
155+
throw invalid_source_file_exceptiont("SUPPORT FUNCTION GENERATION ERROR");
155156
}
156157

157158
if(language_files.final(goto_model.symbol_table))
158159
{
159-
msg.error() << "FINAL STAGE CONVERSION ERROR" << messaget::eom;
160-
throw 0;
160+
throw invalid_source_file_exceptiont("FINAL STAGE CONVERSION ERROR");
161161
}
162162

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

src/goto-programs/initialize_goto_model.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Daniel Kroening, [email protected]
1313
#define CPROVER_GOTO_PROGRAMS_INITIALIZE_GOTO_MODEL_H
1414

1515
#include "goto_model.h"
16+
#include <string>
1617

1718
class cmdlinet;
1819
class message_handlert;

0 commit comments

Comments
 (0)