3 ms·
> Why is not having stdout automatically an error condition? In UNIX the file handle an opened file gets is the next available, lowest number. Closing stdout
by bsdetector 12y ago
> Why is not having stdout automatically an error condition?
In UNIX the file handle an opened file gets is the next available, lowest number. Closing stdout means that the program opens a file and it gets file handle 1 instead of a higher number. Then it writes something to stdout, which is an alias for file handle 1, but instead it writes to the opened file.
I believe this caused some security bugs in passwd or maybe su where you could run it without stderr and "Password:" would be written to the passwd file instead of stderr. ...but these specifics are beside the point, which is that it is next to impossible to anticipate the problems an unhandled error can create.
Java's checked exceptions can be annoying when you have to add some extra "throws X" or handle every case, but my experience is that I never had the slightest doubt over how a method could fail or what needed to be done to handle errors. For unchecked exceptions maybe you have a point, although their failure mode for unhandled errors is still to abort the program rather than to continue on with undefined behavior as in Go.