From a1aefce6e45f30d292dc82a8e1b16c025219985c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Wed, 24 Jan 2018 12:10:03 +0100 Subject: [PATCH] Guard against CLR exceptions when translating exceptions Partially fixes #1138, need to decide what to do about structured exceptions. --- .../internal/catch_exception_translator_registry.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/internal/catch_exception_translator_registry.cpp b/include/internal/catch_exception_translator_registry.cpp index 77f74a88..78b9c573 100644 --- a/include/internal/catch_exception_translator_registry.cpp +++ b/include/internal/catch_exception_translator_registry.cpp @@ -33,6 +33,17 @@ namespace Catch { return Catch::Detail::stringify( [exception description] ); } #else + // Compiling a mixed mode project with MSVC means that CLR + // exceptions will be caught in (...) as well. However, these + // do not fill-in std::current_exception and thus lead to crash + // when attempting rethrow. + // /EHa switch also causes structured exceptions to be caught + // here, but they fill-in current_exception properly, so + // at worst the output should be a little weird, instead of + // causing a crash. + if (std::current_exception() == nullptr) { + return "Non C++ exception. Possibly a CLR exception."; + } return tryTranslators(); #endif }