Skip to content

Commit bbc8518

Browse files
committed
Implementation of a erroneous user input exception class.
1 parent 6fd77f4 commit bbc8518

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/cbmc/cbmc_main.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ Author: Daniel Kroening, [email protected]
2525
#include <iostream>
2626
#endif
2727

28+
#include <iostream>
29+
30+
#include <util/exception_utils.h>
31+
2832
#ifdef IREP_HASH_STATS
2933
extern unsigned long long irep_hash_cnt;
3034
extern unsigned long long irep_cmp_cnt;
@@ -41,9 +45,11 @@ int wmain(int argc, const wchar_t **argv_wide)
4145
int main(int argc, const char **argv)
4246
{
4347
#endif
44-
cbmc_parse_optionst parse_options(argc, argv);
48+
try
49+
{
50+
cbmc_parse_optionst parse_options(argc, argv);
4551

46-
int res=parse_options.main();
52+
int res = parse_options.main();
4753

4854
#ifdef IREP_HASH_STATS
4955
std::cout << "IREP_HASH_CNT=" << irep_hash_cnt << '\n';
@@ -52,4 +58,9 @@ int main(int argc, const char **argv)
5258
#endif
5359

5460
return res;
61+
}
62+
catch(invalid_user_input_exceptiont &e)
63+
{
64+
std::cerr << e.what() << std::endl;
65+
}
5566
}

src/util/exception_utils.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*******************************************************************\
2+
3+
Module: Exception helper utilities
4+
5+
Author: Fotis Koutoulakis, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#ifndef CPROVER_UTIL_EXCEPTION_UTILS_H
10+
#define CPROVER_UTIL_EXCEPTION_UTILS_H
11+
12+
#include <string>
13+
14+
class invalid_user_input_exceptiont
15+
{
16+
std::string reason;
17+
std::string option;
18+
std::string correct_input;
19+
20+
public:
21+
invalid_user_input_exceptiont(
22+
std::string reason,
23+
std::string option,
24+
std::string correct_input)
25+
: reason(reason), option(option), correct_input(correct_input)
26+
{
27+
}
28+
29+
std::string what() const noexcept
30+
{
31+
std::string res;
32+
res += "\nInvalid User Input Exception\n";
33+
res += "Option: " + option + "\n";
34+
res += reason;
35+
// Print an optional correct usage message assuming correct input parameters have been passed
36+
correct_input.empty() ? "\n" : res += " Try: " + correct_input + "\n";
37+
return res;
38+
}
39+
};
40+
41+
#endif // CPROVER_UTIL_EXCEPTION_UTILS_H

0 commit comments

Comments
 (0)