[vtkusers] VTK: Python error messages vs. exceptions

Nico Schlömer nico.schloemer at gmail.com
Fri Jun 1 15:25:38 EDT 2012


Hi all,

when using VTK's Python interface, I often notice that if things don't
go as expected, e.g., when vtkXMLUnstructuredFileReader is instructed
to read a nonexistent file, the code doesn't raise exceptions, but
prints error messages to the screen and continues as normal.

Try, for example:

from vtk import vtkXMLUnstructuredGridReader
reader = vtkXMLUnstructuredGridReader()
reader.SetFileName( 'mynonexistentfile.vtu' )
reader.Update()

The output will be

================ *snip* ================
ERROR: In /build/buildd/vtk-5.8.0/IO/vtkXMLReader.cxx, line 219
vtkXMLUnstructuredGridReader (0x3344e90): Error opening file
mynonexistentfile.vtu

ERROR: In /build/buildd/vtk-5.8.0/Filtering/vtkExecutive.cxx, line 756
vtkStreamingDemandDrivenPipeline (0x33478d0): Algorithm
vtkXMLUnstructuredGridReader(0x3344e90) returned failure for request:
vtkInformation (0x334e000)
  Debug: Off
  Modified Time: 69
  Reference Count: 1
  Registered Events: (none)
  Request: REQUEST_INFORMATION
  FORWARD_DIRECTION: 0
  ALGORITHM_AFTER_FORWARD: 1
================ *snap* ================

Due to this behavior, I get exceptions messages at the weirdest places
in my code (namely where the grid data is tried to be used).

Question: Is there any way to have VTK raise RuntimeError()s (or
similar) instead of just printing a message to the screen?
Alternatively, would there be any way to determine if an operation
went alright? (So far I haven't found return codes or similar.)

Cheers,
Nico



More information about the vtkusers mailing list