Skip to content

Commit 0eae491

Browse files
author
thk123
committed
Adjustments to exception printing
1 parent 25da0c4 commit 0eae491

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
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, kroening@kroening.com
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"
@@ -722,24 +724,40 @@ void symex_target_equationt::SSA_stept::output(
722724
out << "Guard: " << from_expr(ns, "", guard) << '\n';
723725
}
724726

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

src/goto-symex/symex_target_equation.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,6 @@ inline bool operator<(
329329
return &(*a)<&(*b);
330330
}
331331

332-
std::string unwrap_exception(
333-
const std::exception &e,
334-
int level = 0,
335-
std::string message = "");
332+
std::string unwrap_exception(const std::exception &e, int level = 0);
336333

337334
#endif // CPROVER_GOTO_SYMEX_SYMEX_TARGET_EQUATION_H

0 commit comments

Comments
 (0)