Hi Willi,<div><br></div><div>You can capture errors globally and send them to a log file,</div><div>by using e.g. vtkFileOutputWindow. Or you can write a custom</div><div>OutputWindow class that pops up a modal dialog box and</div>
<div>requires your customers to press "Okay" or "Cancel" before</div><div>proceeding.</div><div><br></div><div> - David<br><br><div class="gmail_quote">On Wed, Jan 9, 2013 at 11:56 AM, Willi Huber <span dir="ltr"><<a href="mailto:w.huber@ymail.com" target="_blank">w.huber@ymail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td valign="top" style="font:inherit"><p>Hey David,</p>
<p>yeah it was the right problem you are assuming. <br>
Is there a way to catch errors like this or do I have to tell my "customers" to copy what they can read (if they can read it) in the popup window?<br>
In my opinion this kind of error handling ain't a good solution if wrapping is a feature VTK offers. Can it be stopped that my app is going to be killed in such a harsh way?</p>
<p>Cheers,<br>
Willi</p>
</td></tr></tbody></table> <div>
<div>
<br>
<div style="font-family:times new roman,new york,times,serif;font-size:12pt">
<font face="Tahoma">
<hr size="1">
<b>
<span style="font-weight:bold">From:</span>
</b>
David Gobbi <<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>>; <br>
<b>
<span>To:</span>
</b>
Willi Huber <<a href="mailto:surfersparadise85-vtk@yahoo.com" target="_blank">surfersparadise85-vtk@yahoo.com</a>>; <br>
<b>
<span>Cc:</span>
</b>
<a href="mailto:vtkusers@vtk.org" target="_blank">vtkusers@vtk.org</a> <<a href="mailto:vtkusers@vtk.org" target="_blank">vtkusers@vtk.org</a>>; <br>
<b>
<span>Subject:</span>
</b>
Re: [vtkusers] Python observer handling <br>
<b>
<span style="font-weight:bold">Sent:</span>
</b>
Wed, Jan 9, 2013 6:15:34 PM <br>
</font><div><div class="h5">
<br>
<table cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td valign="top" style="font:inherit">Hi Willi,<br><br>I quickly ran your python code (on my Mac), and saw an error like this<br>in the console:<br><br>ERROR: In vtkDemandDrivenPipeline.cxx, line 816<br>
vtkStreamingDemandDrivenPipeline (0x1044d38a0): Input for connection<br>index 0 on input port index 0 for algorithm<br>vtkPainterPolyDataMapper(0x1044cf970) is of type vtkImageData, but a<br>vtkPolyData is required.<br><br>
So in my case, it wasn't the mapper that generated this error: it was<br>the mapper's executive, which is a different object. Also, many of<br>the VTK mappers delegate to other VTK mappers, and because these<br>
delegate mappers are created internally you will not be able to add<br>
observers to them. I'm not saying this is a good thing... it is a bad<br>thing, obviously, but ErrorObservers cannot always be used<br>successfully with mappers. On the positive side, ErrorObservers
work<br>nicely with readers.<br><br>For your code specifically, I'm guessing that you are seeing an error<br>because you are using an image as input to a vtkPolyDataMapper.<br><br> - David<br><br><br>On Wed, Jan 9, 2013 at 9:20 AM, Willi Huber<br>
<<a>surfersparadise85-vtk@yahoo.com</a>> wrote:<br>> Hello all,<br>><br>> I know exception handling in VTK has been discussed quite a while so I don't<br>> want to add insult to an injury.<br>><br>
> Since David Gobbi very often posted his code:<br>><br>> ==== python code ====<br>> import vtk<br>><br>> class ErrorObserver:<br>><br>> def __init__(self):<br>> self.__ErrorOccurred = False<br>
> self.__ErrorMessage = None<br>> self.CallDataType = 'string0'<br>><br>> def
__call__(self, obj, event, message):<br>> self.__ErrorOccurred = True<br>> self.__ErrorMessage = message<br>><br>> def ErrorOccurred(self):<br>> occ = self.__ErrorOccurred<br>> self.__ErrorOccurred = False<br>
> return occ<br>><br>> def ErrorMessage(self):<br>> return self.__ErrorMessage<br>><br>> e = ErrorObserver()<br>><br>> a = vtk.vtkImageReader()<br>> a.AddObserver('ErrorEvent', e)<br>
><br>> print "doing update"<br>> a.Update()<br>> if e.ErrorOccurred():<br>> print e.ErrorMessage()<br>><br>> ==== python code ====<br>><br>><br>> Unfortunately it is not working as intended. I tried this code which<br>
> obviously had to fail:<br>><br>> ==== python code ====<br>><br>>
mapper = vtk.vtkPolyDataMapper()<br>> mapper.AddObserver('ErrorEvent', e)<br>> mapper.SetInputConnection(reader.GetOutputPort()) #reader is of type<br>> vtkMetaImageReader<br>> mapper.Update()<br>><br>
> if e.ErrorOccurred():<br>> print e.ErrorMessage()<br>> else:<br>> print "No Error"<br>><br>> ==== python code ====<br>><br>> but it didn't. Now I know about this error but I am still curious why it was<br>
> not working as intended.<br>><br>> Shouldn't it print the cause of the error rather than "No Error"?<br>><br>><br>> Everytime I tried this code a vtk warning window poped up which can't be<br>
> read since the whole application dies with some Windows failure handling.<br>> Therefore I was not able to read the error message in the window and had a<br>> tough time finding out about the problem.<br>> Uncommenting renWin.Render() let me read the
error.<br>><br>> Any suggestions what I am doing wrong?<br>><br>><br>> Cheers,<br>><br>> Willi<br></td>
</tr>
</tbody>
</table>
</div></div></div>
</div>
</div>
</blockquote></div><br></div>