Re:Memory management in C programs (2014)
by comex on Tuesday July 19, 2016 @12:16AM
(#12119601)
Any function can overflow the stack. If the object is constructed on the heap, 'new' can fail but will always throw an exception; if you aren't using exceptions it will just crash the process.
[ Parent
| on HN ]
Yeah. That's why I don't say it's a failure condition for a stack-allocated object to overflow the stack. Notice my parent comment said:
> Constructors are resource allocation, so they can always fail.
Which is false.
Re:Memory management in C programs (2014)
by robotresearcher on Tuesday July 19, 2016 @01:45PM
(#12123359)
Can you explain why this is false? If I run out of stack or heap by exceeding the process limit, the constructor must fail. Is this incorrect?
I see your comment above that stack overflows essentially never happen, but having watched it happen, I disagree.
This is not an error that you can reasonably recover from. If you are out of stack, even constructing an exception to throw is likely to fail.
Because the only correct behavior here is to terminate the program immediately, it doesn't matter in the discussion of whether to use exceptions or not.