c++ - make_shared in a try catch - scoping issue -
i need allocate memory, in try/catch, introduces new scope, in variable not available once i'm out of try-scope. what's best way solve this?
try { auto = std::make_unique<someclass>; } catch (std::bad_alloc) { ... } // ... lots of code don't want include in try/catch-scope. something.callsomemethod();
how go solving this?
there specific reason why doing shouldn't work. if code wrote worked way wrote it, calling callsomemethod()
on null object. right way benjamin lindley said, put code in try block. way variable in-scope method call happen if there not bad alloc threw exception.
Comments
Post a Comment