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

Richard Duivenvoorde rdmailings at duif.net
Sat Nov 21 13:52:15 EST 2009


Hi devs,

in the mapserverexport plugin we want the user to be able to load 
another project into QGIS to export:

qgisProjectFile = QFileDialog.getOpenFileName(self.dlg, "Choose a 
QGIS 			Project", ".", "QGIS Project Files (*.qgs);", "...")
     try:
       QgsProject.instance().read(QFileInfo(qgisProjectFile))
     #except QgsException, err:
     except:
       QMessageBox.information(self.dlg, "Not a valid QGIS projectfile.")
       return

While we do filter the view on *.qgs files, it's still possible that the 
user just fills in an excisting NON-qgs-project file.

On the 'read'-call of this (off course) wrong file, qgis halts fiercely 
with:
"
terminate called after throwing an instance of 'QgsException'
   what():  Project file read error: error occurred while parsing 
element at line 1 column 1 for file /home/richard/temp/foo.jpg
Aborted
"

Questions:

- neither the "except QgsException:" nor 'except:" seem to catch the 
exception? Doing someting wrong there? Missing Python interface?

- Isn't it possible to catch this exception? (doing exact the same thing 
via the normal (non python way) 'open project'-dialog, the exception is 
caught: "Project file read error: error occurred while parsing element 
at line 1 column 1 for file /home/richard/temp/foo.jpg"

- shouldn't we load qgs-projects via the python interface? (for valid 
qgs-files it's working ...).

- one option would be to disable the possibility of setting the path by 
keyboard in QFileDialog, but I have to find out how to do that ...

All on QGIS trunk on ubuntu

Regards,

Richard Duivenvoorde


More information about the Qgis-developer mailing list