Home Dashboard Directory Help
Search

Built application crashes on exception rethrow by Dmitry Zhgutov


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 738595
Opened: 4/24/2012 11:10:21 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

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);
Details
Sign in to post a comment.
Posted by MS-Moderator10 [Feedback Moderator] on 4/24/2012 at 9:19 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by MS-Moderator01 on 4/24/2012 at 11:53 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.