Skip to content

Commit 16c0d7b

Browse files
author
thk123
committed
Disable nested exception printing for Windows
Due to bug in the VS2013 C++ compiler, using std::rethrow_if_nested or std::nested_exception is not supported. This disables trying to unwrap the exception and just prints a warning saying the nested exceptionc couldn't be printed. Don't use noexcept directly, pull both part of the nested exception into a separate file to handle discrepancies.
1 parent 17f1afa commit 16c0d7b

File tree

6 files changed

+70
-8
lines changed

6 files changed

+70
-8
lines changed

src/goto-symex/equation_conversion_exceptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class guard_conversion_exceptiont : public std::runtime_error
4040
{
4141
}
4242

43-
const char *what() const noexcept override
43+
const char *what() const optional_noexcept override
4444
{
4545
return error_message.c_str();
4646
}

src/goto-symex/symex_target_equation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Author: Daniel Kroening, kroening@kroening.com
1919
#include <solvers/prop/prop.h>
2020
#include <solvers/prop/literal_expr.h>
2121
#include <solvers/flattening/bv_conversion_exceptions.h>
22+
#include <util/throw_with_nested.h>
2223

2324
#include "goto_symex_state.h"
2425
#include "equation_conversion_exceptions.h"
@@ -437,7 +438,7 @@ void symex_target_equationt::convert_guards(
437438
}
438439
catch(const bitvector_conversion_exceptiont &conversion_exception)
439440
{
440-
std::throw_with_nested(guard_conversion_exceptiont(step, ns));
441+
util_throw_with_nested(guard_conversion_exceptiont(step, ns));
441442
}
442443
}
443444
}

src/solvers/flattening/boolbv_byte_extract.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Daniel Kroening, kroening@kroening.com
1414
#include <util/std_expr.h>
1515
#include <util/byte_operators.h>
1616
#include <util/endianness_map.h>
17+
#include <util/throw_with_nested.h>
1718

1819
#include "flatten_byte_operators.h"
1920
#include "flatten_byte_extract_exceptions.h"
@@ -51,7 +52,7 @@ bvt boolbvt::convert_byte_extract(const byte_extract_exprt &expr)
5152
}
5253
catch(const flatten_byte_extract_exceptiont &byte_extract_flatten_exception)
5354
{
54-
std::throw_with_nested(
55+
util_throw_with_nested(
5556
bitvector_conversion_exceptiont("Can't convert byte_extraction", expr));
5657
}
5758
}

src/solvers/flattening/flatten_byte_extract_exceptions.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class non_const_array_sizet : public flatten_byte_extract_exceptiont
4343
computed_error_message = error_message.str();
4444
}
4545

46-
const char *what() const noexcept override
46+
const char *what() const optional_noexcept override
4747
{
4848
return computed_error_message.c_str();
4949
}
@@ -76,7 +76,7 @@ class non_byte_alignedt : public flatten_byte_extract_exceptiont
7676
computed_error_message = error_message.str();
7777
}
7878

79-
const char *what() const noexcept override
79+
const char *what() const optional_noexcept override
8080
{
8181
return computed_error_message.c_str();
8282
}
@@ -106,7 +106,7 @@ class non_constant_widtht : public flatten_byte_extract_exceptiont
106106
computed_error_message = error_message.str();
107107
}
108108

109-
const char *what() const noexcept override
109+
const char *what() const optional_noexcept override
110110
{
111111
return computed_error_message.c_str();
112112
}
@@ -133,7 +133,7 @@ class non_const_byte_extraction_sizet : public flatten_byte_extract_exceptiont
133133
computed_error_message = error_message.str();
134134
}
135135

136-
const char *what() const noexcept override
136+
const char *what() const optional_noexcept override
137137
{
138138
return computed_error_message.c_str();
139139
}

src/util/throw_with_nested.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*******************************************************************\
2+
3+
Module: util
4+
5+
Author: Diffblue Ltd.
6+
7+
\*******************************************************************/
8+
9+
#ifndef CPROVER_UTIL_THROW_WITH_NESTED_H
10+
#define CPROVER_UTIL_THROW_WITH_NESTED_H
11+
12+
#include <exception>
13+
14+
#ifdef _MSC_VER
15+
#include <stdexcept>
16+
// TODO(tkiley): Nested exception logging not supported on windowsdue to bug
17+
// TODO(tkiley): in MSVC++ Compiler:
18+
// TODO(tkiley): https://blogs.msdn.microsoft.com/vcblog/2016/01/22/vs-2015-update-2s-stl-is-c17-so-far-feature-complete
19+
#define DISABLE_NESTED_EXCEPTIONS
20+
21+
class non_nested_exception_support : public std::runtime_error
22+
{
23+
public:
24+
non_nested_exception_support()
25+
: std::runtime_error("Nested exception printing not supported on Windows")
26+
{
27+
}
28+
};
29+
30+
#endif
31+
32+
template <class T>
33+
#ifdef __GNUC__
34+
__attribute__((noreturn))
35+
#endif
36+
void util_throw_with_nested(T &&t)
37+
{
38+
#ifndef DISABLE_NESTED_EXCEPTIONS
39+
std::throw_with_nested(t);
40+
#else
41+
throw t;
42+
#endif
43+
}
44+
45+
template <class E>
46+
void util_rethrow_if_nested(const E &e)
47+
{
48+
#ifndef DISABLE_NESTED_EXCEPTIONS
49+
std::rethrow_if_nested(e);
50+
#else
51+
// Check we've not already thrown the non_nested_support_exception
52+
if(!dynamic_cast<const non_nested_exception_support *>(&e))
53+
{
54+
throw non_nested_exception_support();
55+
}
56+
#endif
57+
}
58+
59+
#endif // CPROVER_UTIL_THROW_WITH_NESTED_H

src/util/unwrap_nested_exception.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Author: Diffblue Ltd.
88

99
#include "unwrap_nested_exception.h"
1010
#include "suffix.h"
11+
#include "throw_with_nested.h"
1112

1213
#include <string>
1314
#include <exception>
@@ -35,7 +36,7 @@ std::string unwrap_exception(const std::exception &e, int level)
3536

3637
try
3738
{
38-
std::rethrow_if_nested(e);
39+
util_rethrow_if_nested(e);
3940
}
4041
catch(const std::exception &e)
4142
{

0 commit comments

Comments
 (0)