Search

Built application crashes on exception rethrow by Dmitry Zhgutov

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)
0
User(s) can reproduce this bug
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 (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling version

Visual Studio 11 Beta

Steps to reproduce

1. Create empty C++ project (console)
2. Add source file
3. Set configuration to Release
4. Paste the specified source code to that file
5. Build project
6. Run application

Product Language

English

Operating System

Windows 7

Operating System Language

English (US)

Actual results

Built application crashed.

Expected results

Built application works and prints the error message.
File Attachments
0 attachments
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.