Dealing with errors
In the previous examples, we did a little bit of error checking. If we couldn’t get the handle, we showed a message. We did the same thing if we couldn’t write to the console. I realize it’s funny to write to the console that the system cannot write to it (look at line 33, for instance), but you get what I mean here.
But this isn’t good enough if you want to know what’s going on for real. We need a more thorough way of handling errors.
In .NET, we are used to getting exceptions whenever things go wrong. We know how to deal with that. In the low-level world, things are different. When something goes wrong, we get 0
back, and we’re left to deal with it. We could continue with the code without being bothered by the error. We could even ignore the results of a call to an API. However, that would lead to disaster. You should always check and deal with the results of an API call. How to deal with that is something we discuss...