c++ - no-throw exception guarantee and stack overflow -


there several special functions guarantee not throw excpetions, e.g.:

  • destructors
  • swap method

consider following swap implementation, stated in this answer:

friend void swap(dumb_array& first, dumb_array& second) {     using std::swap;       swap(first.msize, second.msize);       swap(first.marray, second.marray);  // if stack overlow occurs here? } 

it uses 2 swap functions - integer , pointer. if second function cause stack overflow? objects become corrupted. guess not std::exception, kind of system exception, win32-exception. cannot guarantee no-throwing, since we're calling function.

but authoritative sources use swap it's ok, no exceptions ever thrown here. why?

in general cannot handle running out of stack. standard doesn't happens if run out of stack, neither talk stack is, how available, etc. oses may let control @ time executable built or when run, of irrelevant if you're writing library code, since have no control of how stack process has, or how has been used before user calls library.

you can assume stack overflow results in os doing something external program. simple os might let go weird (undefined behavior), serious os might blow process away, or if you're unlucky throws implementation-defined exception. don't know whether windows offers seh exception stack overflow, if it's best not enable it.

if you're concerned, can mark swap function noexcept. in conforming implementation, exception tries leave function cause program terminate(). say, fulfils noexcept contract @ cost of taking out program.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -