iutest  1.17.1.0
iutest_exception.hpp
[詳解]
1 //======================================================================
2 //-----------------------------------------------------------------------
13 //-----------------------------------------------------------------------
14 //======================================================================
15 #ifndef INCG_IRIS_IUTEST_EXCEPTION_HPP_B73B2E25_97C8_4DFC_BC32_5E53039A1A64_
16 #define INCG_IRIS_IUTEST_EXCEPTION_HPP_B73B2E25_97C8_4DFC_BC32_5E53039A1A64_
17 
18 //======================================================================
19 // include
20 
21 #if IUTEST_HAS_EXCEPTIONS
22 #include <exception>
23 
24 namespace iutest {
25 namespace detail
26 {
27 
33 inline ::std::string FormatCxxException(const char* description)
34 {
35  iu_stringstream strm;
36  if( description != NULL )
37  {
38  strm << "C++ exception with description \"" << description << "\"";
39  }
40  else
41  {
42  strm << "Unknown C++ exception";
43  }
44  return strm.str();
45 }
46 
47 } // end of namespace detail
48 } // end of namespace iutest
49 
50 #if IUTEST_HAS_SEH && IUTEST_HAS_EXCEPTIONS
51 #include <iomanip>
52 
53 namespace iutest {
54 namespace detail
55 {
56 
60 class seh_exception : public ::std::exception
61 {
62 public:
63  seh_exception() : ::std::exception() {}
64  explicit seh_exception(const char *const& _What) : ::std::exception(_What) {}
65 public:
66  static void translator(DWORD code, _EXCEPTION_POINTERS* ep)
67  {
68  IUTEST_UNUSED_VAR(ep);
69  iu_stringstream strm;
70 #if IUTEST_HAS_IOMANIP
71  strm << "SEH exception with code 0x" << ::std::setbase(16) << code;
72 #else
73  strm << "SEH exception with code " << code;
74 #endif
75  throw seh_exception(strm.str().c_str());
76  }
77  static int should_process_through_break_and_cppexceptions(DWORD code)
78  {
79  bool should_handle = true;
80  // break point と C++ 例外はハンドリングしない
81  if( code == EXCEPTION_BREAKPOINT )
82  should_handle = false;
83  if( code == kCxxExceptionCode )
84  should_handle = false;
85  return should_handle ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;
86  }
87 public:
88  static const DWORD kCxxExceptionCode = 0xe06d7363;
89 };
90 
91 template<typename T>
92 void seh_passthrough(T func)
93 {
94  _EXCEPTION_POINTERS* ep = NULL;
95  __try
96  {
97  (func)();
98  }
99  __except( ep = GetExceptionInformation()
100  , seh_exception::should_process_through_break_and_cppexceptions(GetExceptionCode()) )
101  {
102  seh_exception::translator(GetExceptionCode(), ep);
103  }
104 }
105 
106 
107 } // end of namespace detail
108 } // end of namespace iutest
109 
110 #endif
111 
112 #endif
113 
114 #endif // INCG_IRIS_IUTEST_EXCEPTION_HPP_B73B2E25_97C8_4DFC_BC32_5E53039A1A64_
iutest_config.hpp
iris unit test config
iutest
iutest root namespace
Definition: iutest_charcode.hpp:31