Let's say I have class that acts as a "smart pointer" and releases some kind of system resource when destroyed.
class Resource{
protected:
ResourceHandle h;
public:
Resource(ResourceHandle handle)
:h(handle){
}
~Resource(){
if (h)
releaseResourceHandle(h);//external function, probably from OS
}
};
And I have some function that returns value used for initialization of "Resource":
ResourceHandle allocateHandle();
Now, if I do this in my code:
Resource resource(allocateHandle());
AND allocateHandle() throws an exception, what exactly will happen? Will the crash occur during construction of Resource() or before the construction?
Common sense tells me that because exception is thrown before allocateHandle returns, execution won't even enter Resource() constructor, but I'm not exactly sure about it. Is this a correct assumption?