4 ms·
I'm having a hard time making it fail. Even with Printf, in the output it tells you what you did wrong instead of returning an error. In fact, the only _print
by jagger27 8y ago
I'm having a hard time making it fail. Even with Printf, in the output it tells you what you did wrong instead of returning an error.
In fact, the only _print function I could get to fail was Fprintf by sending an already closed file. I suppose if it was somehow not allowed to write to stdout the other functions might fail. But I'm not sure.
_, err := fmt.Printf("Hello %d", "world")
fmt.Println(err)
>> Hello %!d(string=world)
>> <nil>
- ianlancetaylor 8y agoYes, the various fmt.Print functions only return an error if Write on the underlying Writer returns an error.
- TheDong 8y agoHere you go: https://play.golang.org/p/0vGdejrjm5H https://play.golang.org/p/0vGdejrjm5H To reproduce the key lines here: os.Stdout.Close() _, err := fmt.Println("foo") You can also close stdout from outside the program, use ptrace to cause the write call to fail, or a number of other things.