cprover
throw_with_nested.h
Go to the documentation of this file.
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 windows due to a bug
17 // TODO(tkiley): in MSVC++ Compiler (diffblue/cbmc#2104):
18 // TODO(tkiley): https://blogs.msdn.microsoft.com/vcblog/2016/01/22/vs-2015-update-2s-stl-is-c17-so-far-feature-complete
19 
20 #define DISABLE_NESTED_EXCEPTIONS
21 
22 class non_nested_exception_support : public std::runtime_error
23 {
24 public:
25  non_nested_exception_support()
26  : std::runtime_error("Nested exception printing not supported on Windows")
27  {
28  }
29 };
30 
31 #endif
32 
33 template <class T>
34 #ifdef __GNUC__
35 __attribute__((noreturn))
36 #endif
38 {
39 #ifndef DISABLE_NESTED_EXCEPTIONS
40  std::throw_with_nested(t);
41 #else
42  throw t;
43 #endif
44 }
45 
46 template <class E>
47 void util_rethrow_if_nested(const E &e)
48 {
49 #ifndef DISABLE_NESTED_EXCEPTIONS
50  std::rethrow_if_nested(e);
51 #else
52  // Check we've not already thrown the non_nested_support_exception
53  if(!dynamic_cast<const non_nested_exception_support *>(&e))
54  {
55  throw non_nested_exception_support();
56  }
57 #endif
58 }
59 
60 #endif // CPROVER_UTIL_THROW_WITH_NESTED_H
STL namespace.
int __gcc_m64 __attribute__((__vector_size__(8), __may_alias__))
void util_throw_with_nested(T &&t)
void util_rethrow_if_nested(const E &e)