c++ - catch(...) does not catch all exceptions -
i've run problem regarding exceptions.
the code shown below,
try { auto = set_difference(allinterfaces.begin(), allinterfaces.end(), eths.begin(), eths.end(), newcards.begin()); } catch(...) { cout << "exception thrown << endl; } i know set_difference() throwing exception programs exits , grab block doesn't grab exception. there way grab exception? thought grab should work.
thanks help.
set_difference write elements unique either of input sets output range pass in. it's responsibility ensure that range big plenty contain result. otherwise, you'll walk off beyond bounds of range, resulting in undefined behavior. no exception thrown when happens, best indicator can hope assertion failure in unoptimized builds (and there's no guarantee either).
assuming newcards container supports push_back, easiest way prevent utilize std::back_insert_iterator, phone call push_back every time object assigned it.
auto = set_difference(allinterfaces.begin(), allinterfaces.end(), eths.begin(), eths.end(), std::back_inserter(newcards)); the other options available std::front_insert_iterator (calls push_front()) , std::insert_iterator (calls insert()). take 1 suits needs best.
c++ exception-handling
No comments:
Post a Comment