4 ms·
Most of the reasoning here seems to be based on 1) that "out of memory" is the only exception worth talking about, and 2) the only thing you want to do is abort
by unfamiliar 11y ago
Most of the reasoning here seems to be based on 1) that "out of memory" is the only exception worth talking about, and 2) the only thing you want to do is abort the program at that point.
I don't think either of these are true. Some libraries make liberal use of exceptions, as a design decision. If your text editor tries to open an enormous file, you don't want it to crash, you want it to deallocate all of the memory it consumed for that file and then fall back with an error message.
I don't think the point about inlining is reasonable either: I wouldn't expect a fully optimised build to give me a full stack trace, that is what debug builds are for.
>If the exception is meant to signal the fact that the memory is finished, where are we allocating the stack trace?
If this is really a concern, allocate some memory at the start of execution that you can use in the event of a crash.
- joosters 11y agoUnless you have carefully configured your OS, 'out of memory' exceptions are essentially worthless. This is because most systems work using 'optimistic' memory management, where it is not known (or checked) whether there is enough free memory available at the time of the malloc() call. The problem comes later, at any time when a random instruction tries to access the memory and the OS finds that it has no RAM available.
- imtringued 11y agoOf course we should eat the poison and then go to the hospital. The naive texteditor should just check the size of the file before loading it into memory instead of trying to recover from a crash.
- xsmasher 11y agoAgreed; in my line of work (mobile games) an out of memory exception is the least useful, because the place that threw is not necessarily in the offending system that ate all of the memory. Getting stack traces for other exceptions IS useful - our code is full of assertions that throw when invariant assumptions are violated, and knowing the stack trace is useful for tracking down what system is misbehaving.