Skip to content

Commit e855a50

Browse files
add exception handling to easier diagnose #7418
Signed-off-by: Nikolaj Bjorner <[email protected]>
1 parent 5168a13 commit e855a50

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/api/api_solver.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ extern "C" {
655655
result = to_solver_ref(s)->check_sat(num_assumptions, _assumptions);
656656
}
657657
catch (z3_exception & ex) {
658-
to_solver_ref(s)->set_reason_unknown(eh);
658+
to_solver_ref(s)->set_reason_unknown(eh, ex);
659659
to_solver(s)->set_eh(nullptr);
660660
if (mk_c(c)->m().inc()) {
661661
mk_c(c)->handle_exception(ex);
@@ -751,8 +751,8 @@ extern "C" {
751751
try {
752752
to_solver_ref(s)->get_unsat_core(core);
753753
}
754-
catch (...) {
755-
to_solver_ref(s)->set_reason_unknown(eh);
754+
catch (std::exception& ex) {
755+
to_solver_ref(s)->set_reason_unknown(eh, ex);
756756
to_solver(s)->set_eh(nullptr);
757757
if (core.empty())
758758
throw;
@@ -877,7 +877,7 @@ extern "C" {
877877
}
878878
catch (z3_exception & ex) {
879879
to_solver(s)->set_eh(nullptr);
880-
to_solver_ref(s)->set_reason_unknown(eh);
880+
to_solver_ref(s)->set_reason_unknown(eh, ex);
881881
_assumptions.finalize(); _consequences.finalize(); _variables.finalize();
882882
mk_c(c)->handle_exception(ex);
883883
return Z3_L_UNDEF;

src/solver/check_sat_result.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ void check_sat_result::set_reason_unknown(event_handler& eh) {
3939
}
4040
}
4141

42+
void check_sat_result::set_reason_unknown(event_handler& eh, std::exception& ex) {
43+
switch (eh.caller_id()) {
44+
case UNSET_EH_CALLER:
45+
if (reason_unknown() == "")
46+
set_reason_unknown(ex.what());
47+
break;
48+
default:
49+
set_reason_unknown(eh);
50+
break;
51+
}
52+
}
53+
4254
proof* check_sat_result::get_proof() {
4355
if (!m_log.empty() && !m_proof) {
4456
SASSERT(is_app(m_log.back()));

src/solver/check_sat_result.h

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class check_sat_result {
6969
virtual std::string reason_unknown() const = 0;
7070
virtual void set_reason_unknown(char const* msg) = 0;
7171
void set_reason_unknown(event_handler& eh);
72+
void set_reason_unknown(event_handler& eh, std::exception& ex);
7273
virtual void get_labels(svector<symbol> & r) = 0;
7374
virtual ast_manager& get_manager() const = 0;
7475

0 commit comments

Comments
 (0)