Hi,<br><br>I am trying to catch the exception by vtkSTLReader (e.g. to read a non-exist STL file), so that the vtkOutputWindow will not show up. I added two observer events (vtkCommand::ErrorEvent and vtkCommand::WarningEvent) to the reader, then use Try...Catch. It looks that the error event was caught, since the error message was printed on the screen; but the vtkOutputWindow is also displayed while the "Update()" is executed.<br>
<br> vtkMyObserver *errObserver = vtkMyObserver::New();<br><br> vtkSTLReader *stlReader;<br> stlReader = vtkSTLReader::New();<br> stlReader->SetFileName("abc.stl"); // random name which will be sure to throw an exception<br>
stlReader->AddObserver(vtkCommand::ErrorEvent,errObserver);<br> stlReader->AddObserver(vtkCommand::WarningEvent,errObserver);<br> stlReader->AddObserver(vtkCommand::AbortCheckEvent,errObserver);<br><br>
try {<br> stlReader->Update(); <br> }<br> catch (...){<br> }<br><br> if (errObserver->GetVTKError()) {<br> cout << "Caught an vtkSTLReader exception \n";<br> return false;<br>
}<br><br>However, the same sequence of code works perfectly for vtkPolyDataReader. I only saw the error message, while the vtkOutputWindow was not shown at all.<br><br> vtkMyObserver *errObserver = vtkMyObserver::New();<br>
<br>
vtkPolyDataReader *vtkReader;<br>
vtkReader = vtkSTLReader::New();<br>
vtkReader->SetFileName("abc.vtk"); // random name which will be sure to throw an exception<br>
vtkReader->AddObserver(vtkCommand::ErrorEvent,errObserver);<br>
vtkReader->AddObserver(vtkCommand::WarningEvent,errObserver);<br>
vtkReader->AddObserver(vtkCommand::AbortCheckEvent,errObserver);<br>
<br>
try {<br>
stlReader->Update(); <br>
}<br>
catch (...){<br>
}<br>
<br>
if (errObserver->GetVTKError()) {<br>
cout << "Caught an vtkPolyDataReader exception \n";<br>
return false;<br>
}<br><br><br>Any comments or suggestions are appreciated.<br><br><br>Thanks<br><br><br>Eugene<br>