Faced a very unusual problem. And what's interesting is that it happens only in one case when unit tests are debugging (if you run this code OUT of the unit test debugging cycle, then everything is fine - everything works as expected).
I have the following c ++ / cli code:
MngdClass^ create_mngd_obj() { try { native_class.build_object(); return gcnew MngdClass(native_class.get_object()); } catch (const NativeException& e) { int i = 0; } } Here is the native code that throws an exception (note that it is in a separate native c ++ library):
struct NativeException { const std::string message; NativeException(const std::string& message_) : message(message_) { } }; void NativeClass() { throw NativeException("O la la"); } So, if you try to break through this code in unit tests, a loop will occur. Namely, such a sequence will be performed with the emissions of exceptions (I do not understand why the stack promotion does not occur):
native_class.build_object(); native_class.get_object(); If the code is not debugged in unit tests, everything happens fine. Throw an exception that is safely caught by the handler.