Debugging an OpenGL application can be difficult. But OpenGL does provide ways to make debugging more reasonable.
OpenGL requires its functions to check their parameters for mistakes or inconsistencies, and emit errors should these occur. If an error occurs, in the vast majority of cases, the function emitting the error will have no effect.
Because error checking is a very manual process, many OpenGL implementations provide access to Debug Output. This functionality is a powerful mechanism for handling testing these kinds of errors without being explicit about it. There are also a number of Debugging Tools available to help track down OpenGL errors and other issues.
The OpenGL error mechanism does not test all possible incorrect uses of the API; this is mainly for performance reasons. Most untested mistakes result in improper rendering and must be manually found, though debugging tools can help in these cases too.