When using GetStdHandle() function I can understand you need to make sure that you have a valid Handle to be able to write (output) and read (input) to the console. What I don't understand, is whether obtaining those handles would ever fail? MSDN tells me that I could get INVALID_HANDLE_VALUE or NULL. I have never received those values? Clearly if either write or read handles did produce an error my program should exit?

This brings me to the STD_ERROR_HANDLE. Is it really necessary to use this handle or even quit a program if this returned an error? This handle is not as important as the two I mentioned earlier?

I am new to this and just need a better understanding of these handles.