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.
As other answers have mentioned, your code should generally be within the `try/catch` block, since it doesn't have any meaning if the exception is caught. I'm not sure what your reason is for not wanting to include the code in the `try/catch`, since you're implying `something.callSomeMethod()` depends on `lots of code`, and `lots of code` depends on `std::make_unique`. If `lots of code` isn't dependent, you can delay `std::make_unique` until after `lots of code`.

I think it might be worth clarifying, the purpose of exceptions is to abort and handle an exceptional situation. The exceptional situation is that execution of following code can be impacted. So, any code that would be impacted, or transitively code that depends on it, should be included in the `try/catch` block. This is the minimal scope, by definition, and it's the scope you should use. Nothing more, nothing less.

Sometimes the code to handle an exception can be shared across functions that throw exceptions, but it's still generally best to narrow the scope and write the necessary specific handling code for each one.

It might be worth noting that almost nothing can be done for `std::bad_alloc`, so it's generally not an exception worth catching. Also, you should generally catch exceptions by reference unless you have a reason to do otherwise. So, your code should look something like this...

```
try {

    auto something = std::make_unique<SomeClass>;    

    // ... lots of code I don't want to include in the try/catch-scope.

    something.callSomeMethod();
}

catch (std::exception& e) {

    // you dun goofed...
}

```