Catching opengl errors

Hi all, what would be the recommended way to handle errors that occur inside vtk, specifically connected with opengl errors?
I’m creating a volume with dimensions that exceed my available VRAM, and I get the opengl and vtk error printed, but how can I catch them inside the code?
I tried using vtkObject->AddObserver(vtkCommand::ErrorEvent, vtkCommand) and vtkCommand::WarningEvent on all elements of the pipeline, but that didn’t catch the error.

The printed error:

Failed to allocate 3D texture.1 OpenGL errors detected
  0 : (1285) Out of memory


ERROR: In .../VTK-9.0.1/Rendering/VolumeOpenGL2/vtkVolumeTexture.cxx, line 746
vtkVolumeTexture (0x5586665a3140): Texture 3D allocation failed! 

vtkOutputWindow (or its specific sub-class) invokes the vtkCommand::ErrorEvent when an error like the one you show is triggered. This means you’d have to provide an output window and set up observers for that instance.