Home > database >  Why does fmt.Print() returns an error if no one handles it
Why does fmt.Print() returns an error if no one handles it

Time:11-19

I am often tormented by the question, why does fmt.Print() return an error?

I have never met a situation where I needed it.

In Java and Python, printing to stdout usually does not returns an error. In C#, printing to stdout can cause OOMException.

This, in theory, may be OOM, but there is no point in trying to write something then cause this will be an unrecoverable panic and the program most likely will be killed.

Or maybe this is necessary so that the program can understand that the exit is closed? You can't detect if the process down the pipe has terminated without writing to it, right?

Has anyone ever had to handle this error?

CodePudding user response:

Printing to stdout can return an error if, for instance, stdout is closed while printing. This is especially relevant if stdout is redirected to a pipe or to a file.

Most applications ignore this error though.

  • Related