Question: I just ran vagrant provision in a futile attempt at getting my customized synced\_folders directive to work and now my whole guest box is wiped out.

Is this normal? I don't see any references to Vagrant docs about this behavior.

As per the [doc](http://docs.vagrantup.com/v2/provisioning/):

> 
> Provisioners in Vagrant allow you to automatically install software, alter configurations, and more on the machine as part of the vagrant up process.
> 
> 
> 

The only thing I have in my config provision shell commands are installation commands. Nothing about wiping anything out.

I do have app.vm.provision for puppet that sets fqdn, user name and box name (along with the normal module\_path, manifests\_path and manifests\_file). Maybe this caused things to be reset?

Answer: 
There is a specific reason why what you are doing *shouldn't* work. If the code you wrote worked the way you wrote it, then you would be calling `callSomeMethod()` on a null object. The right way to do it as Benjamin Lindley said, is to put that code in your try block. That way the variable is in-scope but the method call will only happen if there was not a bad alloc that threw an exception.
For posterity, and in case you needed to do something else in your `try` block that would *not* result in an invalid pointer (because, as has been mentioned there is a reason what you're trying to do doesn't work). If you're trying to do something else and still want to execute your operations on `something` afterward, the following code will do what you want:

```
#include <iostream>

#include <memory>
#include <utility>

using namespace std;

int main()
{
    class SomeClass { public: int a; void callSomeMethod() const {} };

    std::unique_ptr<SomeClass> something{};

    try {
        something = std::move(std::make_unique<SomeClass>());

        // operation that might throw other_exception
    }
    catch (const other_exception& e) {
        std::cout << "bad" << std::endl;
    }
    // ... lots of code I don't want to include in the try/catch-scope.
    something->callSomeMethod();

    return 0;
}

```