The following code leads to application crash:#include <iostream>namespace{ enum ExitCode { exit_code_succeeded = 0, exit_code_failed }; template <typename RethrowHandler> void handleExceptionSafely(RethrowHandler handle_exception) /* throw () */ { try { handle_exception(); } catch (...) { std::cout << "unhandled exception\n"; } } template <typename Operation, typename RethrowHandler> ExitCode exceptionsToExitCode(Operation perform, RethrowHandler handle_exception) /* throw () */ { try { perform(); return exit_code_succeeded; } catch (...) { handleExceptionSafely(handle_exception); } return exit_code_failed; } template <typename Operation> ExitCode exceptionsToExitCode(Operation perform) /* throw () */ { return exceptionsToExitCode(perform, []{ }); } void testFunction() { throw 0; }}int main(){ auto exit_code = exceptionsToExitCode(testFunction, []{ throw; }); if (exit_code == exit_code_succeeded) { std::cout << "succeeded\n"; } else { std::cout << "failed\n"; } return exit_code;}Application works when you make the following change:auto exit_code = exceptionsToExitCode([]{ throw 0; }, []{ throw; });Or:void perform() { throw 0; }void handle() { throw; }auto exit_code = exceptionsToExitCode(perform, handle);
Visual Studio/Team Foundation Server/.NET Framework Tooling version
Steps to reproduce
Product Language
Operating System
Operating System Language
Actual results
Expected results
Please wait...