[vtkusers] Catch Exceptions of vtkSTLReader

Eugene Guo yguo2006 at gmail.com
Wed Feb 25 19:43:12 EST 2009


Hi,

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.

    vtkMyObserver *errObserver = vtkMyObserver::New();

    vtkSTLReader    *stlReader;
    stlReader = vtkSTLReader::New();
    stlReader->SetFileName("abc.stl"); // random name which will be sure to
throw an exception
    stlReader->AddObserver(vtkCommand::ErrorEvent,errObserver);
    stlReader->AddObserver(vtkCommand::WarningEvent,errObserver);
    stlReader->AddObserver(vtkCommand::AbortCheckEvent,errObserver);

    try {
    stlReader->Update();
    }
    catch (...){
    }

    if (errObserver->GetVTKError()) {
        cout << "Caught an vtkSTLReader exception \n";
        return false;
    }

However, the same sequence of code works perfectly for vtkPolyDataReader. I
only saw the error message, while the vtkOutputWindow was not shown at all.

   vtkMyObserver *errObserver = vtkMyObserver::New();

    vtkPolyDataReader    *vtkReader;
    vtkReader = vtkSTLReader::New();
    vtkReader->SetFileName("abc.vtk"); // random name which will be sure to
throw an exception
    vtkReader->AddObserver(vtkCommand::ErrorEvent,errObserver);
    vtkReader->AddObserver(vtkCommand::WarningEvent,errObserver);
    vtkReader->AddObserver(vtkCommand::AbortCheckEvent,errObserver);

    try {
    stlReader->Update();
    }
    catch (...){
    }

    if (errObserver->GetVTKError()) {
        cout << "Caught an vtkPolyDataReader exception \n";
        return false;
    }


Any comments or suggestions are appreciated.


Thanks


Eugene
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090225/1b65ad46/attachment.htm>


More information about the vtkusers mailing list