Hacker News new | ask | show | jobs
by kyllo 4189 days ago
It honestly hadn't occurred to me that printing to stdout could fail, or that I'd need to check its return value to ensure it was successful. Can you think of an situation where that might happen? And if so, why doesn't println throw an exception?

On the other hand, a side effect like writing to a file or inserting to a database can easily fail, but those of course throw exceptions.

1 comments

Output redirected to a file and file being already closed, for one. Or anyway, stdout being closed midway due to many other possible reasons: this is (probably) why printf returns a number of bytes written or -1, for example: http://www.cplusplus.com/reference/cstdio/printf/