Skip to content

Commit 5ecc69f

Browse files
author
thk123
committed
Adjustments to exception printing
1 parent 1639e0f commit 5ecc69f

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

src/goto-symex/symex_target_equation.cpp

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Author: Daniel Kroening, [email protected]
1818
#include <solvers/prop/prop.h>
1919
#include <solvers/prop/literal_expr.h>
2020
#include <solvers/flattening/bv_conversion_exceptions.h>
21+
#include <util/string_utils.h>
22+
#include <util/suffix.h>
2123

2224
#include "goto_symex_state.h"
2325
#include "equation_conversion_exceptions.h"
@@ -724,24 +726,40 @@ void symex_target_equationt::SSA_stept::output(
724726
out << "Guard: " << from_expr(ns, "", guard) << '\n';
725727
}
726728

727-
std::string
728-
unwrap_exception(const std::exception &e, int level, std::string message)
729+
/// Given a potentially nested exception, produce a string with all of nested
730+
/// exceptions information. If a nested exception string contains new lines
731+
/// then the newlines are indented to the correct level.
732+
/// \param e: The outer exeception
733+
/// \param level: How many exceptions have already been unrolled
734+
/// \return A string with all nested exceptions printed and indented
735+
std::string unwrap_exception(const std::exception &e, int level)
729736
{
730-
// messaget message(get_message_handler());
731-
// message.error().source_location=symex.last_source_location;
732-
// message.error() << error_str << messaget::eom;
733-
message += std::string(level, ' ') + "exception: " + e.what() + "\n";
737+
const std::string msg = e.what();
738+
std::vector<std::string> lines;
739+
split_string(msg, '\n', lines, false, true);
740+
std::ostringstream message_stream;
741+
message_stream << std::string(level, ' ') << "exception: ";
742+
join_strings(
743+
message_stream, lines.begin(), lines.end(), "\n" + std::string(level, ' '));
744+
734745
try
735746
{
736747
std::rethrow_if_nested(e);
737748
}
738749
catch(const std::exception &e)
739750
{
740-
unwrap_exception(e, level + 1, message);
751+
std::string nested_message = unwrap_exception(e, level + 1);
752+
// Some exception messages already end in a new line (e.g. as they have
753+
// dumped an irept. Most do not so add a new line on.
754+
if(!has_suffix(nested_message, "\n"))
755+
{
756+
message_stream << '\n';
757+
}
758+
message_stream << nested_message;
741759
}
742760
catch(...)
743761
{
744762
UNREACHABLE;
745763
}
746-
return message;
764+
return message_stream.str();
747765
}

src/goto-symex/symex_target_equation.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -331,17 +331,6 @@ inline bool operator<(
331331

332332
std::string unwrap_exception(
333333
const std::exception &e,
334-
int level = 0,
335-
std::string message = "");
336-
337-
class guard_conversion_exceptiont : public std::runtime_error
338-
{
339-
public:
340-
guard_conversion_exceptiont(const symex_target_equationt::SSA_stept &step) :
341-
std::runtime_error("Error converting guard for step"), step(step)
342-
{}
343-
private:
344-
symex_target_equationt::SSA_stept step;
345-
};
334+
int level = 0);
346335

347336
#endif // CPROVER_GOTO_SYMEX_SYMEX_TARGET_EQUATION_H

0 commit comments

Comments
 (0)