Skip to content

Commit 017c1b0

Browse files
committed
Modify parse_options_baset::main to handle exceptions.
1 parent 66fc8a1 commit 017c1b0

File tree

3 files changed

+31
-26
lines changed

3 files changed

+31
-26
lines changed

src/cbmc/cbmc_main.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,9 @@ int wmain(int argc, const wchar_t **argv_wide)
4141
int main(int argc, const char **argv)
4242
{
4343
#endif
44-
try
45-
{
46-
cbmc_parse_optionst parse_options(argc, argv);
44+
cbmc_parse_optionst parse_options(argc, argv);
4745

48-
int res = parse_options.main();
46+
int res = parse_options.main();
4947

5048
#ifdef IREP_HASH_STATS
5149
std::cout << "IREP_HASH_CNT=" << irep_hash_cnt << '\n';
@@ -54,9 +52,4 @@ int main(int argc, const char **argv)
5452
#endif
5553

5654
return res;
57-
}
58-
catch(invalid_user_input_exceptiont &e)
59-
{
60-
std::cerr << e.what() << std::endl;
61-
}
6255
}

src/cbmc/cbmc_parse_options.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,9 @@ class optionst;
7676
"(claim):(show-claims)(floatbv)(all-claims)(all-properties)" // legacy, and will eventually disappear // NOLINT(whitespace/line_length)
7777
// clang-format on
7878

79-
class cbmc_parse_optionst:
80-
public parse_options_baset,
81-
public xml_interfacet,
82-
public messaget
79+
class cbmc_parse_optionst : public parse_options_baset,
80+
public xml_interfacet,
81+
public messaget
8382
{
8483
public:
8584
virtual int doit() override;

src/util/parse_options.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Author: Daniel Kroening, [email protected]
1818
#endif
1919

2020
#include "cmdline.h"
21+
#include "exception_utils.h"
22+
#include "exit_codes.h"
2123
#include "signal_catcher.h"
2224

2325
parse_options_baset::parse_options_baset(
@@ -47,23 +49,34 @@ void parse_options_baset::unknown_option_msg()
4749

4850
int parse_options_baset::main()
4951
{
50-
if(parse_result)
52+
// catch all exceptions here so that this code is not duplicated
53+
// for each tool
54+
try
5155
{
52-
usage_error();
53-
unknown_option_msg();
54-
return EX_USAGE;
56+
if(parse_result)
57+
{
58+
usage_error();
59+
unknown_option_msg();
60+
return EX_USAGE;
61+
}
62+
63+
if(cmdline.isset('?') || cmdline.isset('h') || cmdline.isset("help"))
64+
{
65+
help();
66+
return EX_OK;
67+
}
68+
69+
// install signal catcher
70+
install_signal_catcher();
71+
72+
return doit();
5573
}
56-
57-
if(cmdline.isset('?') || cmdline.isset('h') || cmdline.isset("help"))
74+
catch(invalid_user_input_exceptiont &e)
5875
{
59-
help();
60-
return EX_OK;
76+
std::cerr << e.what() << "\n";
77+
return CPROVER_EXIT_USAGE_ERROR;
6178
}
62-
63-
// install signal catcher
64-
install_signal_catcher();
65-
66-
return doit();
79+
return CPROVER_EXIT_SUCCESS;
6780
}
6881

6982
std::string

0 commit comments

Comments
 (0)