<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;">====&nbsp;python&nbsp;code ====
import vtk

class ErrorObserver:

&nbsp; &nbsp;def __init__(self):
&nbsp; &nbsp; &nbsp; &nbsp;self.__ErrorOccurred = False
&nbsp; &nbsp; &nbsp; &nbsp;self.__ErrorMessage = None
&nbsp; &nbsp; &nbsp; &nbsp;self.CallDataType = 'string0'

&nbsp; &nbsp;def __call__(self, obj, event, message):
&nbsp; &nbsp; &nbsp; &nbsp;self.__ErrorOccurred = True
&nbsp; &nbsp; &nbsp; &nbsp;self.__ErrorMessage = message

&nbsp; &nbsp;def ErrorOccurred(self):
&nbsp; &nbsp; &nbsp; &nbsp;occ = self.__ErrorOccurred
&nbsp; &nbsp; &nbsp; &nbsp;self.__ErrorOccurred = False
&nbsp; &nbsp; &nbsp; &nbsp;return occ

&nbsp; &nbsp;def ErrorMessage(self):
&nbsp; &nbsp; &nbsp; &nbsp;return self.__ErrorMessage

e = ErrorObserver()

a = vtk.vtkImageReader()
a.AddObserver('ErrorEvent', e)

print "doing update"
a.Update()
if e.ErrorOccurred():
&nbsp; &nbsp;print e.ErrorMessage()</pre><pre style="font-family: 'Courier New'; font-size: 10pt;">====&nbsp;python&nbsp;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;">====&nbsp;python&nbsp;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;">&nbsp; &nbsp;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;">&nbsp; &nbsp;print "No Error"</font></div><div><font
 size="2"><pre style="font-size: 10pt; font-family: 'Courier New', courier, monaco, monospace, sans-serif;">====&nbsp;python&nbsp;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>