3 ms·
Really puzzled that you have conflated exceptions ("'x' went wrong, here's the stack") with undefined behavior, crashes and memory corruption. It seems as thou
by sk5t 8y ago
Really puzzled that you have conflated exceptions ("'x' went wrong, here's the stack") with undefined behavior, crashes and memory corruption.
It seems as though you're describing how the world ought to be, and maybe could be, for the writing of pure functions, procedures with provably no side effects, and the like. Well, OK.
However, imagine that you're writing a few bytes to disk. Maybe the device runs out of space halfway through the write, the filesystem was mounted readonly, or the filesystem doesn't like the filename you asked for due to length or case-insensitive overlap with an existing name, or the controller driver glitches out, or permissions are wrong, etc., etc. You cannot anticipate all of these and implement recovery, aside from informing the caller what went wrong, and giving an opportunity to somehow correct the problem elsewhere and retry. Well now you're in the business of not really recovering from the fault, but instead doing something the same or nearly the same as raising an exception and printing the stacktrace.
TBH I have misgivings about even writing up that last paragraph because the alternatives really strain credibility.
- kelnos 8y agoI don't think the parent was suggesting that there's anything wrong with what you wrote in that paragraph. At least IMO that counts as handling the error, vs. just doing nothing and assuming everything is ok. If you have to kick it back to the user and say "sorry, XYZ happened, and there's nothing I can do about it", that absolutely counts as handling the error. Not handling it would be just assuming the file got written properly to disk and then later having to deal with corrupt data.