c++ - Exception within function returning value for constructor -
let's have class acts "smart pointer" , releases kind of system resource when destroyed.
class resource{ protected: resourcehandle h; public: resource(resourcehandle handle) :h(handle){ } ~resource(){ if (h) releaseresourcehandle(h);//external function, os } };
and have function returns value used initialization of "resource":
resourcehandle allocatehandle();
now, if in code:
resource resource(allocatehandle());
and allocatehandle() throws exception, happen? crash occur during construction of resource() or before construction?
common sense tells me because exception thrown before allocatehandle returns, execution won't enter resource() constructor, i'm not sure it. correct assumption?
arguments evaluated before function call -- in case constructor --. therefore, exception thrown before constructor call
Comments
Post a Comment