<html><body><div style="color:#000; background-color:#fff; font-family:arial, helvetica, sans-serif;font-size:10pt"><div><div style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">Hello all,</div><div style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><br></div><div style="font-family: arial, helvetica, sans-serif; font-size: 10pt; background-color: transparent;">I know exception handling in VTK has been discussed quite a while so I don't want to add insult to an injury.</div><div style="font-family: arial, helvetica, sans-serif; font-size: 10pt; background-color: transparent;"><br></div><div style="font-family: arial, helvetica, sans-serif; font-size: 10pt; background-color: transparent;">Since David Gobbi very often posted his code:</div><div style="background-color: transparent;"><pre style="font-family: 'Courier New'; font-size: 10pt;">==== python code ====
import vtk
class ErrorObserver:
def __init__(self):
self.__ErrorOccurred = False
self.__ErrorMessage = None
self.CallDataType = 'string0'
def __call__(self, obj, event, message):
self.__ErrorOccurred = True
self.__ErrorMessage = message
def ErrorOccurred(self):
occ = self.__ErrorOccurred
self.__ErrorOccurred = False
return occ
def ErrorMessage(self):
return self.__ErrorMessage
e = ErrorObserver()
a = vtk.vtkImageReader()
a.AddObserver('ErrorEvent', e)
print "doing update"
a.Update()
if e.ErrorOccurred():
print e.ErrorMessage()</pre><pre style="font-family: 'Courier New'; font-size: 10pt;">==== python code ====</pre><div style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><br></div><div style="font-family: arial, helvetica, sans-serif; font-size: 10pt;">Unfortunately it is not working as intended. I tried this code which obviously had to fail:</div><div style="font-family: arial, helvetica, sans-serif; font-size: 10pt;"><br></div><div style="font-size: 10pt;"><pre style="font-size: 10pt;"><span style="font-family: 'Courier New', courier, monaco, monospace, sans-serif;">==== python code ====</span></pre></div><div><div><font size="2" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif;">mapper = vtk.vtkPolyDataMapper()</font></div><div><font size="2" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif;">mapper.AddObserver('ErrorEvent', e)</font></div><div><font
size="2" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif;">mapper.SetInputConnection(reader.GetOutputPort()) #reader is of type vtkMetaImageReader</font></div><div><font size="2" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif;">mapper.Update()</font></div><div><font size="2" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif;"><br></font></div><div><font size="2" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif;">if e.ErrorOccurred():</font></div><div><font size="2" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif;"> print e.ErrorMessage()</font></div><div><font size="2" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif;">else:</font></div><div><font size="2" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif;"> print "No Error"</font></div><div><font
size="2"><pre style="font-size: 10pt; font-family: 'Courier New', courier, monaco, monospace, sans-serif;">==== python code ====</pre><pre style="font-size: 10pt;"><span style="font-family: arial, helvetica, sans-serif;">but it didn't. Now I know about this error but I am still curious why it was not working as intended.</span></pre><pre style="font-size: 10pt;"><span style="font-family: arial, helvetica, sans-serif;">Shouldn't it print the cause of the error rather than "No Error"?</span></pre><pre style="font-size: 10pt;"><span style="font-family: arial, helvetica, sans-serif;"><br></span></pre><pre style="font-size: 10pt;"><span style="font-family: arial, helvetica, sans-serif;">Everytime I tried this code a vtk warning window poped up which can't be read since the whole application dies with some Windows failure handling. Therefore I was not able to read the error message in the window and had a tough time finding out about the problem.
Uncommenting renWin.Render() let me read the error.</span></pre><pre style="font-size: 10pt;"><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt; background-color: transparent;">Any suggestions what I am doing wrong?</span><br></pre><pre style="font-size: 10pt;"><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt; background-color: transparent;"><br></span></pre><pre style="font-size: 10pt;"><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt; background-color: transparent;">Cheers,</span></pre><pre style="font-size: 10pt;"><span style="font-family: arial, helvetica, sans-serif; font-size: 10pt; background-color: transparent;">Willi</span></pre><pre style="font-size: 10pt;"><span style="font-family: arial, helvetica, sans-serif;"><br></span></pre></font></div></div></div></div></div></body></html>