[Qgis-developer] segfault python: no catch for QgsException?

Richard Duivenvoorde rdmailings at duif.net
Tue Nov 24 16:50:32 EST 2009


He Martin,

Thanks for your answers,

Martin Dobias wrote:
> what QGIS version is that? Here on svn trunk I get just a message box
> with the error message and no crash - supposedly thanks to a last
> resort try...catch block in QgsApplication.

svn trunk ...
doing it with r12220 or 12214, not sure which tree I used ...
Both as a plugin and in the python console Qgis just crashes when I do

from PyQt4.QtCore import *
from PyQt4.QtGui import *
try:
QgsProject.instance().read(QFileInfo('/home/richard/temp/test.dbf'))
except:
	print 'FOUT'  # dutch for 'ERROR' :-)

after I read a valid project into qgis first...

> The exceptions are not recognized in Python because they're not
> wrapped in SIP. Barry had a similar problem few months ago:
> http://lists.osgeo.org/pipermail/qgis-developer/2009-January/005887.html
> 
> I still think we should remove usage of exceptions from QGIS codebase
> - either to make the API simpler and also more Qt-like. But someone
> would have to do it :-)

Removing exceptions? ... How would you handle stuff like above then (or 
do I sound very old-fashioned now ;-) ). Seriously, does Qt have an 
alternative for this?
If there is a good alternative, we could make it a task for people who 
want to start cpp (like me and Werner...) maybe?

> Or eventually prior to opening the file in QGIS you could check
> whether it exists and it's readable (i.e. try to open it).

Yep, I know doing

from xml.dom import minidom
try:
	minidom.parse(unicode('/home/richard/temp/foo.dbf'))
except:
	print 'FOUT'  # dutch for 'ERROR' :-)

will gracefully fail, without a crash, so I think I will do that first, 
before trying to read the file ....

Thanks,

Richard Duivenvoorde


More information about the Qgis-developer mailing list