[vtkusers] Avoiding program crashing when an algorithm does

John Drescher drescherjm at gmail.com
Tue May 15 12:19:07 EDT 2012


On Tue, May 15, 2012 at 12:14 PM, Carlos Delgado
<carlos.m.delgado at gmail.com> wrote:
> Hello:
>
> I have developed an VTK application with a Qt GUI. I am using the
> vtkSelectPolyData class in my program. This algorithm crashes when not
> finding the edge, and a vtkOutputWindow is open showing an error
> message and the program crashes.
>
> My question is: How can I avoid program crashing when the algorithm
> does? I have tried a try/catch structure to handle the problem, but it
> didn't help or I didn't implemented it properly. Could anyone give me
> some tip on how to approach this problem?
>

Although I recommend trying to fix the algorithm bug, in Qt I have put
a try / catch in the notify member of the application class. This will
catch most application exceptions:

bool smStudyManagerApp::notify( QObject *pObject, QEvent *pEvent )
{
	try {
		return Superclass::notify(pObject,pEvent);
	}
	catch( smException & e) {
		e.Print(std::cerr);
	}
	catch( ... )
	{
		std::cerr << "An unknown exception occurred" << std::endl;
	}
	return false;
}

John



More information about the vtkusers mailing list