Sign in to follow this  
stu_pb

Exception Object Scope

Recommended Posts

In the following code, what scope does the MyException object belong to. Does it go out of scope when the catch block is complete, the application exits or will this leak memory?
class MyException
{
private:
    std::string _message;
public:
    std::string Message() { return _message; }

    MyException(std::string error)
    {
        _message = error;
    }
};

void SomeFunction();

void main()
{
    try{
        SomeFunction();
    }
    catch(MyException e)
    {
        MessageBox(NULL,e.Message(),"ERROR",MB_OK);
    }
}

void SomeFunction()
{
    throw MyException("My error Message");
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this