Refer to khronos documentation for error handling via the callback mechanism.
Although you are able to write a try { } catch { } block around your C++ code, OpenGL calls do not throw C++ exceptions, but instead they do accumulate errors that can be either manually read, or you can setup and use an error callback using glDebugMessageCallback(). Out of the box, OpenGL does not throw exceptions, but you could emulate exceptions from within such a callback by throwing a custom exception from within the callback.
See Khronos Documentation at the Wiki : Catching errors (the easy way)
"The debug output feature provides a simple method for your application to be notified via an application-defined message callback function when an OpenGL error (or other interesting event) occurs within the driver. Simply enable debug output, register a callback, and wait for it to be called with a DEBUG_TYPE_ERROR message.
use glGetError() calls around your application to catch and localize the causes of OpenGL errors (and the need to conditionally compile them into debug builds to avoid the performance hit in optimized builds). The feature can even ensure that message callback functions are invoked on the same thread and within the very same call stack as the GL call that triggered the GL error (or performance warning).
A simple example showing how to utilize debug message callbacks (e.g. for detecting OpenGL errors):
void GLAPIENTRY MessageCallback( GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam ) { fprintf( stderr, “GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n”, ( type == GL_DEBUG_TYPE_ERROR ? “** GL ERROR **” : “” ), type, severity, message ); } // During init, enable debug output glEnable ( GL_DEBUG_OUTPUT ); glDebugMessageCallback( MessageCallback, 0 );"