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

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -