c++ - Catching exceptions from a constructor's initializer list -


here's curious one. have class a. has item of class b, want initialize in constructor of using initializer list, so:

class {     public:     a(const b& b): mb(b) { };      private:     b mb; }; 

is there way catch exceptions might thrown mb's copy-constructor while still using initializer list method? or have initialize mb within constructor's braces in order have try/catch?

have read of http://weseetips.wordpress.com/tag/exception-from-constructor-initializer-list/)

edit: after more digging, these called "function try blocks".

i confess didn't know either until went looking. learn every day! don't know if indictment of how little use c++ these days, lack of c++ knowledge, or byzantine features litter language. ah - still :)

to ensure people don't have jump site, syntax of function try block constructors turns out be...

c::c() try : init1(), ..., initn() {   // constructor } catch(...) {   // handle exception } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -