Skip to content

Commit b2c6da2

Browse files
Some basic exception types
1 parent 752fc31 commit b2c6da2

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

src/cbmc/bv_cbmc.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Author: Daniel Kroening, [email protected]
1010

1111
#include <util/arith_tools.h>
1212
#include <util/replace_expr.h>
13+
#include <util/invariant_utils.h>
1314

1415
bvt bv_cbmct::convert_waitfor(const exprt &expr)
1516
{

src/cbmc/cbmc_solvers.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ cbmc_solverst::solvert* cbmc_solverst::get_smt1(smt1_dect::solvert solver)
206206
{
207207
if(solver==smt1_dect::solvert::GENERIC)
208208
{
209-
error() << "please use --outfile" << eom;
210-
throw 0;
209+
throw user_exceptiont("please use --outfile");
211210
}
212211

213212
smt1_dect *smt1_dec=
@@ -245,8 +244,7 @@ cbmc_solverst::solvert* cbmc_solverst::get_smt1(smt1_dect::solvert solver)
245244

246245
if(!out)
247246
{
248-
error() << "failed to open " << filename << eom;
249-
throw 0;
247+
IO_EXCEPTION_WITH_FILENAME("failed to open", filename);
250248
}
251249

252250
smt1_convt *smt1_conv=

src/cbmc/show_vcc.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Author: Daniel Kroening, [email protected]
2222

2323
#include <util/json.h>
2424
#include <util/json_expr.h>
25+
#include <util/invariant_utils.h>
2526

2627
void bmct::show_vcc_plain(std::ostream &out)
2728
{
@@ -150,7 +151,7 @@ void bmct::show_vcc()
150151
{
151152
of.open(filename);
152153
if(!of)
153-
throw "failed to open file "+filename;
154+
throw system_exceptiont("failed to open file "+filename);
154155
}
155156

156157
std::ostream &out=have_file?of:std::cout;

src/util/exception_utils.h

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*******************************************************************\
2+
3+
Module: Exception helper utilities
4+
5+
Author: Peter Schrammel, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#ifndef CPROVER_UTIL_EXCEPTION_UTILS_H
10+
#define CPROVER_UTIL_EXCEPTION_UTILS_H
11+
12+
#include "invariant.h"
13+
14+
/// A logic error to be used for OS-related errors (I/O etc)
15+
class system_exceptiont: public std::logic_error
16+
{
17+
public:
18+
system_exceptiont(
19+
const std::string &_reason):
20+
std::logic_error(_reason)
21+
{
22+
}
23+
};
24+
25+
/// A logic error to be used for user interface errors
26+
class ui_exceptiont: public std::logic_error
27+
{
28+
public:
29+
ui_exceptiont(
30+
const std::string &_reason):
31+
std::logic_error(_reason)
32+
{
33+
}
34+
};
35+
36+
/// A user interface exception with source locations
37+
class input_src_exceptiont: public ui_exceptiont
38+
{
39+
public:
40+
input_src_exceptiont(
41+
const source_locationt &_source_location,
42+
const std::string &_reason):
43+
ui_exceptiont(_reason),
44+
source_location(_source_location)
45+
{
46+
}
47+
48+
source_locationt source_location;
49+
};
50+
51+
#endif // CPROVER_UTIL_EXCEPTION_UTILS_H

0 commit comments

Comments
 (0)